Add in all useful claims
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user