From 42215e7d28d6144e5a19f77ddc060c42b7afdad5 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 23 Jan 2020 20:51:02 +0800 Subject: ... --- Timeline/Auth/MyAuthenticationHandler.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Timeline/Auth') diff --git a/Timeline/Auth/MyAuthenticationHandler.cs b/Timeline/Auth/MyAuthenticationHandler.cs index f5dcd697..5bae5117 100644 --- a/Timeline/Auth/MyAuthenticationHandler.cs +++ b/Timeline/Auth/MyAuthenticationHandler.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; using System; +using System.Globalization; using System.Linq; using System.Security.Claims; using System.Text.Encodings.Web; @@ -30,13 +31,13 @@ namespace Timeline.Auth public class MyAuthenticationHandler : AuthenticationHandler { private readonly ILogger _logger; - private readonly IUserService _userService; + private readonly IUserTokenManager _userTokenManager; - public MyAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IUserService userService) + public MyAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IUserTokenManager userTokenManager) : base(options, logger, encoder, clock) { _logger = logger.CreateLogger(); - _userService = userService; + _userTokenManager = userTokenManager; } // return null if no token is found @@ -78,9 +79,10 @@ namespace Timeline.Auth try { - var userInfo = await _userService.VerifyToken(token); + var userInfo = await _userTokenManager.VerifyToken(token); var identity = new ClaimsIdentity(AuthenticationConstants.Scheme); + identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userInfo.Id.ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64)); identity.AddClaim(new Claim(identity.NameClaimType, userInfo.Username, ClaimValueTypes.String)); identity.AddClaims(UserRoleConvert.ToArray(userInfo.Administrator).Select(role => new Claim(identity.RoleClaimType, role, ClaimValueTypes.String))); -- cgit v1.2.3