Skip to content

Instantly share code, notes, and snippets.

@jtrimm007
Created December 29, 2021 21:16
Show Gist options
  • Save jtrimm007/8f4124f023752628b5595cb0ebf9f518 to your computer and use it in GitHub Desktop.
Save jtrimm007/8f4124f023752628b5595cb0ebf9f518 to your computer and use it in GitHub Desktop.
How to Create a Custom Token for Authentication
var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("KeyForSignInSecret@1234"));
var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);
var tokeOptions = new JwtSecurityToken(
issuer: url,
audience: url,
claims: new List<Claim>(),
expires: DateTime.Now.AddMinutes(30),
signingCredentials: signinCredentials
);
var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment