I have a scenario in which I need to set the clock skew for JWT bearer tokens. but whatever I do, the code ignores my settings.
I have tried configuring it in multiple different sections of the Dependency Injection file in the Infrastructure Layer, but it ignores all of them.
I have this at the moment:
services.AddIdentityServer(options =>
{
options.IssuerUri = configuration.GetSection("MyCurrentDomainName")?.Value;
options.Authentication.CookieLifetime = TimeSpan.FromDays(999);
options.Authentication.CookieSlidingExpiration = true;
}).AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
services.Configure<JwtBearerOptions>(configuration =>
{
configuration.TokenValidationParameters.ClockSkew = TimeSpan.FromSeconds(9875664);
});
services.TryAddEnumerable(ServiceDescriptor
.Singleton<IConfigureOptions<JwtBearerOptions>, ConfigureBearerOptions>());
Services.AddTransient<IProfileService, ProfileService>();
services.TryAddEnumerable(ServiceDescriptor
.Singleton<IPostConfigureOptions<JwtBearerOptions>, ConfigureJwtBearerOptions>());
The code ignores my configurations and sets the clock skew to its default 5 minutes.
In the last line of the above code, I have a PostConfigurationOption, and I have set the clock skew there as well, it runs the code, but when the WebUI layer calls for the authentication, the clock skew will default to 5 minutes.
What am I doing wrong here?