Skip to content

Instantly share code, notes, and snippets.

@brunohbrito

brunohbrito/creatersa.cs

Last active Feb 29, 2020
Embed
What would you like to do?
public static void Run()
{
var tokenHandler = new JsonWebTokenHandler();
var key = new RsaSecurityKey(RSA.Create(2048))
{
KeyId = Guid.NewGuid().ToString()
};
Jwt.SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.RsaSsaPssSha256);
Console.WriteLine($"{tokenHandler.CreateToken(Jwt)}{Environment.NewLine}");
}
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",
};
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.