Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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));
        }