コード例 #1
0
        public JwtSecurityToken BuildToken(string sub, JsonWebTokenSettings jsonWebTokenSettings, string[] roles = null)
        {
            var claims = new List <Claim>();

            claims.AddJti();
            claims.AddSub(sub);
            if (roles != null && roles.Length > 0)
            {
                claims.AddRoles(roles);
            }

            return(GetJwtSecurityToken(claims, jsonWebTokenSettings));
        }
コード例 #2
0
 private static JwtSecurityToken GetJwtSecurityToken(IEnumerable <Claim> claims, JsonWebTokenSettings jsonWebTokenSettings)
 {
     return(new JwtSecurityToken(
                jsonWebTokenSettings.Issuer,
                jsonWebTokenSettings.Audience,
                claims,
                DateTime.UtcNow,
                jsonWebTokenSettings.Expires,
                jsonWebTokenSettings.SigningCredentials
                ));
 }