Skip to content

Commit cac6f2e

Browse files
committed
Ensure JwtBearer settings are validated and lifetime checked
- Throw ArgumentNullException if JwtBearerSettings options are null in JwtBearerService constructor. - Always enable token lifetime validation in JWT Bearer authentication, regardless of ExpirationTime setting.
1 parent 8deef46 commit cac6f2e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/SimpleAuthentication/JwtBearer/JwtBearerService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class JwtBearerService(IOptions<JwtBearerSettings> jwtBearerSettingsOptio
1515
/// <summary>
1616
/// Gets the JWT Bearer settings used by this service.
1717
/// </summary>
18-
protected JwtBearerSettings JwtBearerSettings { get; } = jwtBearerSettingsOptions.Value;
18+
protected JwtBearerSettings JwtBearerSettings { get; } = jwtBearerSettingsOptions?.Value ?? throw new ArgumentNullException(nameof(jwtBearerSettingsOptions));
1919

2020
/// <inheritdoc />
2121
public virtual Task<string> CreateTokenAsync(string userName, IList<Claim>? claims = null, string? issuer = null, string? audience = null, DateTime? absoluteExpiration = null)

src/SimpleAuthentication/SimpleAuthenticationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static void CheckAddJwtBearer(AuthenticationBuilder builder, IConfigurationSecti
112112
ValidateIssuerSigningKey = true,
113113
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings.SecurityKey)),
114114
RequireExpirationTime = true,
115-
ValidateLifetime = settings.ExpirationTime.GetValueOrDefault() > TimeSpan.Zero,
115+
ValidateLifetime = true,
116116
ClockSkew = settings.ClockSkew
117117
};
118118
});

0 commit comments

Comments
 (0)