コード例 #1
0
        JwtSecurityToken CreateJwtSecurityToken(User user)
        {
            var claims = new List <Claim>()
            {
                new Claim(JwtRegisteredClaimNames.Jti, Config.Id),
                new Claim(JwtRegisteredClaimNames.Sub, user.Name),
                new Claim(ClaimTypes.Sid, Config.Id),
                new Claim(ClaimTypes.Name, user.Name),
                new Claim(ClaimTypes.Role, user.Role)
            };

            var token = new JwtSecurityToken(
                issuer: Config.Issuer,
                audience: Config.Audience,
                claims: claims,
                expires: DateTime.UtcNow.AddDays(7),
                signingCredentials: new SigningCredentials(KeyStore.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)
                );

            return(token);
        }