aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-12 21:38:43 +0800
committercrupest <crupest@outlook.com>2020-11-12 21:38:43 +0800
commitee1b2b5b100268aa510257a1a2cd4cd03f9fc72b (patch)
tree221a2af5008e180e180f5400f127a0d404ed5158 /BackEnd/Timeline/Auth/MyAuthenticationHandler.cs
parent2c6b812382e04956793d90ba4148dd4aa7da3b70 (diff)
downloadtimeline-ee1b2b5b100268aa510257a1a2cd4cd03f9fc72b.tar.gz
timeline-ee1b2b5b100268aa510257a1a2cd4cd03f9fc72b.tar.bz2
timeline-ee1b2b5b100268aa510257a1a2cd4cd03f9fc72b.zip
...
Diffstat (limited to 'BackEnd/Timeline/Auth/MyAuthenticationHandler.cs')
-rw-r--r--BackEnd/Timeline/Auth/MyAuthenticationHandler.cs9
1 files changed, 5 insertions, 4 deletions
diff --git a/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs b/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs
index 3c97c329..b5e22a14 100644
--- a/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs
+++ b/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs
@@ -17,6 +17,7 @@ namespace Timeline.Auth
{
public const string Scheme = "Bearer";
public const string DisplayName = "My Jwt Auth Scheme";
+ public const string PermissionClaimName = "Permission";
}
public class MyAuthenticationOptions : AuthenticationSchemeOptions
@@ -78,12 +79,12 @@ namespace Timeline.Auth
try
{
- var userInfo = await _userTokenManager.VerifyToken(token);
+ var user = await _userTokenManager.VerifyToken(token);
var identity = new ClaimsIdentity(AuthenticationConstants.Scheme);
- identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userInfo.Id!.Value.ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64));
- identity.AddClaim(new Claim(identity.NameClaimType, userInfo.Username, ClaimValueTypes.String));
- identity.AddClaims(UserRoleConvert.ToArray(userInfo.Administrator!.Value).Select(role => new Claim(identity.RoleClaimType, role, ClaimValueTypes.String)));
+ 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.ToString(), ClaimValueTypes.String)));
var principal = new ClaimsPrincipal();
principal.AddIdentity(identity);