public ClaimsPrincipal Validate(string token) { SecurityToken securityToken; ClaimsPrincipal claims = new JwtSecurityTokenHandler() .ValidateToken(token, new TokenValidationParameters() { ValidateIssuer = true, ValidIssuer = AuthOptions.ISSUER, ValidateAudience = true, ValidAudience = AuthOptions.AUDIENCE, ValidateLifetime = true, IssuerSigningKey = AuthOptions.GetSecurityKey(), ValidateIssuerSigningKey = true }, out securityToken); return(claims); }
public string Generate(IEnumerable <Claim> claims, DateTime expires) { var jwt = new JwtSecurityToken(issuer: AuthOptions.ISSUER, audience: AuthOptions.AUDIENCE, claims: claims, expires: expires, signingCredentials: new SigningCredentials(AuthOptions.GetSecurityKey(), SecurityAlgorithms.HmacSha256) ); return(new JwtSecurityTokenHandler().WriteToken(jwt)); }