Add in all useful claims

This commit is contained in:
2025-07-24 21:56:22 -07:00
parent c167cbc267
commit 3c02bf0bc6
+8 -3
View File
@@ -1,6 +1,7 @@
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims; using System.Security.Claims;
using System.Text; using System.Text;
using Auth.Entities;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
namespace Auth.Services { namespace Auth.Services {
@@ -11,14 +12,18 @@ namespace Auth.Services {
public static string TokenSecretKey = ""; public static string TokenSecretKey = "";
public static string TokenName = "mistox_session"; 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 tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.UTF8.GetBytes(TokenSecretKey); var key = Encoding.UTF8.GetBytes(TokenSecretKey);
var tokenDiscriptor = new SecurityTokenDescriptor { var tokenDiscriptor = new SecurityTokenDescriptor {
Subject = new ClaimsIdentity([ Subject = new ClaimsIdentity([
new Claim(ClaimTypes.NameIdentifier, accountID.ToString()), new Claim(ClaimTypes.NameIdentifier, account.ID.ToString()),
new Claim(ClaimTypes.IsPersistent, StayLoggedIn.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), Expires = DateTime.UtcNow.AddDays(7),
IssuedAt = DateTime.UtcNow, IssuedAt = DateTime.UtcNow,