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 | ffe44ba70c9e5c6a01179c7e2f4185543cbc441c (patch) | |
tree | 67128b91d6cfd08c54c9e745e7bf2abbdf1f20f4 /BackEnd/Timeline/Auth | |
parent | 5ad1b1f0191ee1131e7808c8fcb0484ba29c0d4d (diff) | |
download | timeline-ffe44ba70c9e5c6a01179c7e2f4185543cbc441c.tar.gz timeline-ffe44ba70c9e5c6a01179c7e2f4185543cbc441c.tar.bz2 timeline-ffe44ba70c9e5c6a01179c7e2f4185543cbc441c.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);
|