Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created March 8, 2021 02:03
Embed
What would you like to do?
public async Task<string> CreateJwtTokenString(string accessToken, string refreshToken)
{
var jwtSigningKey = await _keyVaultService.GetJwtSigningKey();
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSigningKey));
var signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);
var secToken = new JwtSecurityToken(
issuer: _configuration["Issuer"],
audience: _configuration["Audience"],
claims: new List<Claim>
{
new Claim("accessToken", await _cryptoService.Encrypt(accessToken)),
new Claim("refreshToken", await _cryptoService.Encrypt(refreshToken))
},
notBefore: null,
expires: DateTime.Now.AddDays(1),
signingCredentials);
return new JwtSecurityTokenHandler().WriteToken(secToken);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment