mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-05-01 18:43:49 +08:00
refactor: Use ClockSkew options For prevent add default value (5min) to life time token
This commit is contained in:
parent
0b47559441
commit
bb7aaa2edb
@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
namespace BuildingBlocks.Jwt;
|
namespace BuildingBlocks.Jwt;
|
||||||
|
|
||||||
using Duende.IdentityServer.EntityFramework.Entities;
|
using Duende.IdentityServer.EntityFramework.Entities;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
public static class JwtExtensions
|
public static class JwtExtensions
|
||||||
{
|
{
|
||||||
@ -20,7 +21,11 @@ public static class JwtExtensions
|
|||||||
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
|
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
|
||||||
{
|
{
|
||||||
options.Authority = jwtOptions.Authority;
|
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.RequireHttpsMetadata = jwtOptions.RequireHttpsMetadata;
|
||||||
options.MetadataAddress= jwtOptions.MetadataAddress;
|
options.MetadataAddress= jwtOptions.MetadataAddress;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -44,14 +44,11 @@ public static class Config
|
|||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
ClientId = "client",
|
ClientId = "client",
|
||||||
|
|
||||||
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
|
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
|
||||||
|
|
||||||
ClientSecrets =
|
ClientSecrets =
|
||||||
{
|
{
|
||||||
new Secret("secret".Sha256())
|
new Secret("secret".Sha256())
|
||||||
},
|
},
|
||||||
|
|
||||||
AllowedScopes =
|
AllowedScopes =
|
||||||
{
|
{
|
||||||
IdentityServerConstants.StandardScopes.OpenId,
|
IdentityServerConstants.StandardScopes.OpenId,
|
||||||
@ -60,7 +57,9 @@ public static class Config
|
|||||||
Constants.StandardScopes.PassengerApi,
|
Constants.StandardScopes.PassengerApi,
|
||||||
Constants.StandardScopes.BookingApi,
|
Constants.StandardScopes.BookingApi,
|
||||||
Constants.StandardScopes.IdentityApi
|
Constants.StandardScopes.IdentityApi
|
||||||
}
|
},
|
||||||
|
AccessTokenLifetime = 3600, // authorize the client to access protected resources
|
||||||
|
IdentityTokenLifetime = 3600 // authenticate the user
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user