public string Create(IJwtClaimInfo claimInfo) { var expires = this.systemClock.Now.AddDays(this.jwtConfig.JwtExpiresDate); var token = new JwtSecurityToken( issuer: this.jwtConfig.JwtIssuer, audience: this.jwtConfig.JwtAudience, claims: this.GetClaims(claimInfo), expires: expires, signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(this.jwtConfig.JwtSecret)), SecurityAlgorithms.HmacSha256) ); return(this.securityTokenHandler.WriteToken(token)); }
private IEnumerable <Claim> GetClaims(IJwtClaimInfo claimInfo) { // JwtBearerAuthentication 用 yield return(new Claim(JwtRegisteredClaimNames.Jti, claimInfo.UserId)); yield return(new Claim(JwtRegisteredClaimNames.Sub, claimInfo.Name)); yield return(new Claim(JwtRegisteredClaimNames.Email, claimInfo.Email)); // User.Identity プロパティ用 yield return(new Claim(ClaimTypes.Sid, claimInfo.UserId)); yield return(new Claim(ClaimTypes.Name, claimInfo.Name)); yield return(new Claim(ClaimTypes.Locality, claimInfo.CultureInfo.ToString())); yield return(new Claim(ClaimTypes.Email, claimInfo.Email)); }