Created
April 4, 2021 06:35
-
-
Save FacileTechnolab/4e6ea3d97cb72c01f03bb475276fd35e to your computer and use it in GitHub Desktop.
Setting up jwt authentication as default authentication and add token validation options
This file contains 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
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); // => remove default claims | |
services | |
.AddAuthentication(options => | |
{ | |
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | |
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; | |
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | |
}) | |
.AddJwtBearer(cfg => | |
{ | |
cfg.RequireHttpsMetadata = false; | |
cfg.SaveToken = true; | |
cfg.TokenValidationParameters = new TokenValidationParameters | |
{ | |
ValidIssuer = Configuration["JwtIssuer"], | |
ValidAudience = Configuration["JwtIssuer"], | |
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtKey"])), | |
ClockSkew = TimeSpan.Zero // remove delay of token when expire | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment