public string GenerateToken(TokenClaims claims) { var handler = new JwtSecurityTokenHandler(); var creds = new SigningCredentials(Key, SecurityAlgorithms.HmacSha256); var tokenDescriptor = new SecurityTokenDescriptor { Issuer = Issuer, Audience = Issuer, Subject = new ClaimsIdentity(claims.ToClaims()), SigningCredentials = creds, }; var token = handler.CreateToken(tokenDescriptor); return(handler.WriteToken(token)); }
public static TokenClaims ToTokenClaims(this ClaimsPrincipal claimsPrincipal) { return(TokenClaims.FromClaimPrincinpal(claimsPrincipal)); }