From d8f253c6710cb23c632d3fc8a31d4d7d1ee0b9ff Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 11 Dec 2020 21:48:49 +0200 Subject: Authorization key is gotten from appsettings.json (AppSettings/Secret) --- API/Service/UserService.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'API/Service/UserService.cs') diff --git a/API/Service/UserService.cs b/API/Service/UserService.cs index b715f8c..4ace934 100644 --- a/API/Service/UserService.cs +++ b/API/Service/UserService.cs @@ -10,6 +10,7 @@ using Microsoft.IdentityModel.Tokens; using System.Security.Claims; using System; using System.Text; +using Microsoft.Extensions.Configuration; namespace API.Service { @@ -17,11 +18,13 @@ namespace API.Service { private readonly UserDbRepository _userDbRepository; private readonly IMapper _userMapper; + private readonly IConfiguration _appSettings; - public UserService(DevHiveContext context, IMapper mapper) + public UserService(DevHiveContext context, IMapper mapper, IConfiguration appSettings) { this._userDbRepository = new UserDbRepository(context); this._userMapper = mapper; + this._appSettings = appSettings; } public async Task LoginUser(UserDTO userDTO) @@ -31,9 +34,7 @@ namespace API.Service if (user == null) return new NotFoundObjectResult("User does not exist!"); - - // Temporary, TODO: get key from appsettings - var key = Encoding.ASCII.GetBytes(")H@McQfTB?E(H+Mb8x/A?D(Gr4u7x!A%WnZr4t7weThWmZq4KbPeShVm*G-KaPdSz%C*F-Ja6w9z$C&F"); + var key = Encoding.ASCII.GetBytes(_appSettings.GetSection("Secret").Value); var tokenHandler = new JwtSecurityTokenHandler(); var tokenDescriptor = new SecurityTokenDescriptor -- cgit v1.2.3