예제 #1
0
        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));
        }
예제 #2
0
 public static TokenClaims ToTokenClaims(this ClaimsPrincipal claimsPrincipal)
 {
     return(TokenClaims.FromClaimPrincinpal(claimsPrincipal));
 }