aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Auth
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-01-23 20:51:02 +0800
committercrupest <crupest@outlook.com>2020-01-23 20:51:02 +0800
commit42215e7d28d6144e5a19f77ddc060c42b7afdad5 (patch)
tree1e722a0618cdb0fe3f784a0c4100727a5b2b3ece /Timeline/Auth
parent747bf829351c30069647a44f98ac19f1a214370f (diff)
downloadtimeline-42215e7d28d6144e5a19f77ddc060c42b7afdad5.tar.gz
timeline-42215e7d28d6144e5a19f77ddc060c42b7afdad5.tar.bz2
timeline-42215e7d28d6144e5a19f77ddc060c42b7afdad5.zip
...
Diffstat (limited to 'Timeline/Auth')
-rw-r--r--Timeline/Auth/MyAuthenticationHandler.cs10
1 files changed, 6 insertions, 4 deletions
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<MyAuthenticationOptions>
{
private readonly ILogger<MyAuthenticationHandler> _logger;
- private readonly IUserService _userService;
+ private readonly IUserTokenManager _userTokenManager;
- public MyAuthenticationHandler(IOptionsMonitor<MyAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IUserService userService)
+ public MyAuthenticationHandler(IOptionsMonitor<MyAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IUserTokenManager userTokenManager)
: base(options, logger, encoder, clock)
{
_logger = logger.CreateLogger<MyAuthenticationHandler>();
- _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)));