Created
November 4, 2017 13:10
-
-
Save StephanyBatista/68d0071a25307956e170a45d427bced0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string Build() | |
{ | |
var claims = new List<Claim> | |
{ | |
new Claim(JwtRegisteredClaimNames.Sub, this.subject), | |
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), | |
new Claim("NameId", this.nameId) | |
} | |
.Union(this.claims.Select(item => new Claim(item.Key, item.Value))); | |
var token = new JwtSecurityToken( | |
issuer: this.issuer, | |
audience: this.audience, | |
claims: claims, | |
expires: DateTime.UtcNow.AddMinutes(expiryInMinutes), | |
signingCredentials: new SigningCredentials( | |
this.securityKey, | |
SecurityAlgorithms.HmacSha256)); | |
return new JwtSecurityTokenHandler().WriteToken(token); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment