diff options
author | crupest <crupest@outlook.com> | 2021-01-07 20:12:00 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-01-07 20:12:00 +0800 |
commit | 97e6ac51ac4df58cd1229e7974d2b846b192558a (patch) | |
tree | 73a1baa078fa7a38dcdbdd38620bba0ef6a1298f /BackEnd/Timeline/Auth | |
parent | d3c9d0a9335ac6df3e330172b1b1a8a219cbdbaf (diff) | |
download | timeline-97e6ac51ac4df58cd1229e7974d2b846b192558a.tar.gz timeline-97e6ac51ac4df58cd1229e7974d2b846b192558a.tar.bz2 timeline-97e6ac51ac4df58cd1229e7974d2b846b192558a.zip |
refactor: Make mapper a service. Fix #202.
Diffstat (limited to 'BackEnd/Timeline/Auth')
-rw-r--r-- | BackEnd/Timeline/Auth/MyAuthenticationHandler.cs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs b/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs index c57c96bc..e4122c65 100644 --- a/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs +++ b/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs @@ -32,12 +32,14 @@ namespace Timeline.Auth {
private readonly ILogger<MyAuthenticationHandler> _logger;
private readonly IUserTokenManager _userTokenManager;
+ private readonly IUserPermissionService _userPermissionService;
- public MyAuthenticationHandler(IOptionsMonitor<MyAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IUserTokenManager userTokenManager)
+ public MyAuthenticationHandler(IOptionsMonitor<MyAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IUserTokenManager userTokenManager, IUserPermissionService userPermissionService)
: base(options, logger, encoder, clock)
{
_logger = logger.CreateLogger<MyAuthenticationHandler>();
_userTokenManager = userTokenManager;
+ _userPermissionService = userPermissionService;
}
// return null if no token is found
@@ -84,7 +86,9 @@ namespace Timeline.Auth var identity = new ClaimsIdentity(AuthenticationConstants.Scheme);
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64));
identity.AddClaim(new Claim(identity.NameClaimType, user.Username, ClaimValueTypes.String));
- identity.AddClaims(user.Permissions.Select(permission => new Claim(AuthenticationConstants.PermissionClaimName, permission.Permission, ClaimValueTypes.String)));
+
+ var permissions = await _userPermissionService.GetPermissionsOfUserAsync(user.Id);
+ identity.AddClaims(permissions.Select(permission => new Claim(AuthenticationConstants.PermissionClaimName, permission.ToString(), ClaimValueTypes.String)));
var principal = new ClaimsPrincipal();
principal.AddIdentity(identity);
|