Skip to content

Instantly share code, notes, and snippets.

@evgomes
Last active November 6, 2018 23:54
Show Gist options
  • Save evgomes/474a729890a42504a8502c5c0337b40c to your computer and use it in GitHub Desktop.
Save evgomes/474a729890a42504a8502c5c0337b40c to your computer and use it in GitHub Desktop.
Build access token method from the token handler of JWT API.
private AccessToken BuildAccessToken(User user, RefreshToken refreshToken)
{
var accessTokenExpiration = DateTime.UtcNow.AddSeconds(_tokenOptions.AccessTokenExpiration);
var securityToken = new JwtSecurityToken
(
issuer : _tokenOptions.Issuer,
audience : _tokenOptions.Audience,
claims : GetClaims(user),
expires : accessTokenExpiration,
notBefore : DateTime.UtcNow,
signingCredentials : _signingConfigurations.SigningCredentials
);
var handler = new JwtSecurityTokenHandler();
var accessToken = handler.WriteToken(securityToken);
return new AccessToken(accessToken, accessTokenExpiration.Ticks, refreshToken);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment