Add pinCode to TokenDTO

This commit is contained in:
Thomas Fransolet 2023-12-05 14:08:00 +01:00
parent eb0263dee8
commit 0b0b54c6af
2 changed files with 9 additions and 2 deletions

View File

@ -11,5 +11,6 @@ namespace Manager.Interfaces.DTO
public int expires_in { get; set; }
public DateTimeOffset expiration { get; set; }
public string instanceId { get; set; }
public int? pinCode { get; set; }
}
}

View File

@ -13,6 +13,7 @@ using Microsoft.IdentityModel.Tokens;
using Manager.Framework.Business;
using Manager.Interfaces.DTO;
using System.IdentityModel.Tokens.Jwt;
using Manager.Services;
namespace ManagerService.Service.Services
{
@ -24,6 +25,7 @@ namespace ManagerService.Service.Services
private readonly ILogger<TokensService> _logger;
private readonly TokensSettings _tokenSettings;
private readonly ProfileLogic _profileLogic;
private InstanceDatabaseService _instanceService;
private readonly SigningCredentials _signingCredentials;
@ -35,11 +37,12 @@ namespace ManagerService.Service.Services
/// <param name="context">Database context</param>
/// <param name="profileLogic">Profile logic</param>
/// <param name="emailClient">Email client</param>
public TokensService(ILogger<TokensService> logger, IOptions<TokensSettings> tokenSettings, ProfileLogic profileLogic)
public TokensService(ILogger<TokensService> logger, IOptions<TokensSettings> tokenSettings, ProfileLogic profileLogic, InstanceDatabaseService instanceService)
{
_logger = logger;
_tokenSettings = tokenSettings.Value;
_profileLogic = profileLogic;
_instanceService = instanceService;
var key = Encoding.UTF8.GetBytes(_tokenSettings.Secret);
_signingCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature);
@ -73,6 +76,8 @@ namespace ManagerService.Service.Services
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var instance = _instanceService.GetById(user.InstanceId);
return new TokenDTO()
{
access_token = tokenHandler.WriteToken(token),
@ -80,7 +85,8 @@ namespace ManagerService.Service.Services
expiration = new DateTimeOffset(token.ValidTo),
token_type = "Bearer",
scope = Security.Scope,
instanceId = user.InstanceId
instanceId = user.InstanceId,
pinCode = instance.PinCode
};
}
catch (UnauthorizedAccessException ex)