From ffe44ba70c9e5c6a01179c7e2f4185543cbc441c Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 7 Jan 2021 20:12:00 +0800 Subject: refactor: Make mapper a service. Fix #202. --- BackEnd/Timeline/Auth/MyAuthenticationHandler.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'BackEnd/Timeline/Auth/MyAuthenticationHandler.cs') 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 _logger; private readonly IUserTokenManager _userTokenManager; + private readonly IUserPermissionService _userPermissionService; - public MyAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IUserTokenManager userTokenManager) + public MyAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IUserTokenManager userTokenManager, IUserPermissionService userPermissionService) : base(options, logger, encoder, clock) { _logger = logger.CreateLogger(); _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); -- cgit v1.2.3