davidfowl / TodoApi

Todo application with ASP.NET Core Blazor WASM, Minimal APIs and Authentication
MIT License
2.74k stars 411 forks source link

ValidateLifetime JWT #94

Open alfonsovgs opened 2 months ago

alfonsovgs commented 2 months ago

Hi! 👋

I made a modification so that the token expiration time is 1 minute, but the token is still valid.

 var jwtToken = handler.CreateJwtSecurityToken(
     _issuer,
     audience: null,
     identity,
     notBefore: DateTime.Now,
     expires: DateTime.Now.AddMinutes(1), // 👈 updated
     issuedAt: DateTime.Now,
     _jwtSigningCredentials);

I'm not sure if I need to configure this, but when I do, it throws this error: Bearer error="invalid_token",error_description="The signature key was not found"

builder.Services.AddAuthentication().AddJwtBearer(options =>
{
    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateLifetime = true,
    };
});