refactor: Use ClockSkew options For prevent add default value (5min) to life time token

This commit is contained in:
Pc 2023-06-25 13:41:22 +03:30
parent 0b47559441
commit bb7aaa2edb
2 changed files with 9 additions and 5 deletions

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace BuildingBlocks.Jwt;
using Duende.IdentityServer.EntityFramework.Entities;
using Microsoft.IdentityModel.Tokens;
public static class JwtExtensions
{
@ -20,7 +21,11 @@ public static class JwtExtensions
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
{
options.Authority = jwtOptions.Authority;
options.TokenValidationParameters.ValidateAudience = false;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false,
ClockSkew = TimeSpan.FromSeconds(2) // For prevent add default value (5min) to life time token!
};
options.RequireHttpsMetadata = jwtOptions.RequireHttpsMetadata;
options.MetadataAddress= jwtOptions.MetadataAddress;
});

View File

@ -44,14 +44,11 @@ public static class Config
new()
{
ClientId = "client",
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
@ -60,7 +57,9 @@ public static class Config
Constants.StandardScopes.PassengerApi,
Constants.StandardScopes.BookingApi,
Constants.StandardScopes.IdentityApi
}
},
AccessTokenLifetime = 3600, // authorize the client to access protected resources
IdentityTokenLifetime = 3600 // authenticate the user
}
};
}