Last active
March 5, 2023 04:11
-
-
Save changhuixu/35a5a9c2ad95c5ac7cdddf4bcbab4840 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
var jwtTokenConfig = Configuration.GetSection("jwtTokenConfig").Get<JwtTokenConfig>(); | |
services.AddSingleton(jwtTokenConfig); | |
services.AddAuthentication(x => | |
{ | |
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | |
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | |
}).AddJwtBearer(x => | |
{ | |
x.RequireHttpsMetadata = true; | |
x.SaveToken = true; | |
x.TokenValidationParameters = new TokenValidationParameters | |
{ | |
ValidateIssuer = true, | |
ValidIssuer = jwtTokenConfig.Issuer, | |
ValidateIssuerSigningKey = true, | |
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtTokenConfig.Secret)), | |
ValidAudience = jwtTokenConfig.Audience, | |
ValidateAudience = true, | |
ValidateLifetime = true, | |
ClockSkew = TimeSpan.FromMinutes(1) | |
}; | |
}); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment