Last active
May 19, 2024 03:47
-
-
Save dj-nitehawk/27550c40475ea528f5c187050fca9fba to your computer and use it in GitHub Desktop.
Asymmetric JWT token usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bld.Services.AddAuthenticationJwtBearer( | |
s => | |
{ | |
s.SigningKey = "base64 encoded public key"; | |
s.SigningStyle = TokenSigningStyle.Asymmetric; | |
s.KeyIsPemEncoded = true; // only if public key is in PEM format | |
}, | |
b => | |
{ | |
b.TokenValidationParameters.ValidIssuer = "issuer"; | |
b.TokenValidationParameters.ValidAudience = "audience"; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var token = JwtBearer.CreateToken( | |
o => | |
{ | |
o.SigningKey = "base64 encoded private key"; | |
o.SigningStyle = TokenSigningStyle.Asymmetric; | |
o.SigningAlgorithm = SecurityAlgorithms.RsaSha256; | |
o.Issuer = "issuer"; | |
o.Audience = "audience"; | |
o.ExpireAt = DateTime.UtcNow.AddDays(1); | |
o.User.Claims.Add(("Claim Type", "Claim Value")); | |
o.User.Permissions.Add("Perm1", "Perm2", "Perm3"); | |
o.User.Roles.Add("Role1", "Role2"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment