Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get secret key bytes
- var tokenKey = Encoding.UTF8.GetBytes("12345678901234567890123456789012");
- // Create a token descriptor (represents a token, kind of a "template" for token)
- var tokenDescriptor = new SecurityTokenDescriptor
- {
- Expires = DateTime.UtcNow.AddMinutes(10),
- SigningCredentials = new SigningCredentials(
- new SymmetricSecurityKey(tokenKey),
- SecurityAlgorithms.HmacSha256Signature)
- };
- // Create token using that descriptor, serialize it and return it
- var tokenHandler = new JwtSecurityTokenHandler();
- var token = tokenHandler.CreateToken(tokenDescriptor);
- var serializedToken = tokenHandler.WriteToken(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement