Skip to content

Commit

Permalink
Merge pull request #112 from marcominerva/develop
Browse files Browse the repository at this point in the history
Set AuthenticationType of JwtBearer.TokenValidationParameters to SchemeName from the settings
  • Loading branch information
marcominerva authored Jul 11, 2024
2 parents 5077548 + 418f63e commit 2b9e0c5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SimpleAuthentication/JwtBearer/JwtBearerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class JwtBearerService(IOptions<JwtBearerSettings> jwtBearerSettingsOpt

public string CreateToken(string userName, IList<Claim>? claims = null, string? issuer = null, string? audience = null, DateTime? absoluteExpiration = null)
{
claims ??= new List<Claim>();
claims ??= [];
claims.Update(jwtBearerSettings.NameClaimType, userName);
claims.Update(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString());
claims.Remove(JwtRegisteredClaimNames.Aud);
Expand All @@ -37,6 +37,7 @@ public ClaimsPrincipal ValidateToken(string token, bool validateLifetime)
{
var tokenValidationParameters = new TokenValidationParameters
{
AuthenticationType = jwtBearerSettings.SchemeName,
NameClaimType = jwtBearerSettings.NameClaimType,
RoleClaimType = jwtBearerSettings.RoleClaimType,
ValidateIssuer = jwtBearerSettings.Issuers?.Any() ?? false,
Expand Down
1 change: 1 addition & 0 deletions src/SimpleAuthentication/SimpleAuthenticationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static void CheckAddJwtBearer(AuthenticationBuilder builder, IConfigurationSecti
{
options.TokenValidationParameters = new()
{
AuthenticationType = settings.SchemeName,
NameClaimType = settings.NameClaimType,
RoleClaimType = settings.RoleClaimType,
ValidateIssuer = settings.Issuers?.Any() ?? false,
Expand Down

0 comments on commit 2b9e0c5

Please sign in to comment.