Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private static DateTime Now = DateTime.Now;
private static SecurityTokenDescriptor Jwt = new SecurityTokenDescriptor
{
Issuer = "www.mysite.com",
Audience = "your-spa",
IssuedAt = Now,
NotBefore = Now,
Expires = Now.AddHours(1),
Subject = new ClaimsIdentity(new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Email, "meuemail@gmail.com", ClaimValueTypes.Email),
new Claim(JwtRegisteredClaimNames.GivenName, "Bruno Brito"),
new Claim(JwtRegisteredClaimNames.Sub, Guid.NewGuid().ToString())
})
};
private static TokenValidationParameters TokenValidationParams = new TokenValidationParameters
{
ValidIssuer = "www.mysite.com",
ValidAudience = "your-spa",
};
public static void Run()
{
var tokenHandler = new JsonWebTokenHandler();
var key = new ECDsaSecurityKey(ECDsa.Create(ECCurve.NamedCurves.nistP256))
{
KeyId = Guid.NewGuid().ToString()
};
Jwt.SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.EcdsaSha256);
var lastJws = tokenHandler.CreateToken(Jwt);
Console.WriteLine($"{lastJws}{Environment.NewLine}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.