From 3c02bf0bc66b1082b641dd9cad00f67cc040e6c3 Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Thu, 24 Jul 2025 21:56:22 -0700 Subject: [PATCH] Add in all useful claims --- src/Server/Services/jwt.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Server/Services/jwt.cs b/src/Server/Services/jwt.cs index d5e3600..d5a8e31 100644 --- a/src/Server/Services/jwt.cs +++ b/src/Server/Services/jwt.cs @@ -1,6 +1,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; +using Auth.Entities; using Microsoft.IdentityModel.Tokens; namespace Auth.Services { @@ -11,14 +12,18 @@ namespace Auth.Services { public static string TokenSecretKey = ""; public static string TokenName = "mistox_session"; - public static string GenereateJWTToken(int accountID, bool StayLoggedIn) { + public static string GenereateJWTToken(Account account, bool StayLoggedIn) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.UTF8.GetBytes(TokenSecretKey); var tokenDiscriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity([ - new Claim(ClaimTypes.NameIdentifier, accountID.ToString()), - new Claim(ClaimTypes.IsPersistent, StayLoggedIn.ToString()) + new Claim(ClaimTypes.NameIdentifier, account.ID.ToString()), + new Claim(ClaimTypes.Name, account.UserName), + new Claim(ClaimTypes.Email, account.Email), + new Claim(ClaimTypes.Role, account.Role), + new Claim(ClaimTypes.UserData, account.DataServer), + new Claim(ClaimTypes.IsPersistent, StayLoggedIn.ToString()), ]), Expires = DateTime.UtcNow.AddDays(7), IssuedAt = DateTime.UtcNow,