Skip to content

Commit 92b6270

Browse files
committed
Resolved #155
1 parent acbc2f2 commit 92b6270

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Host/Startup/AuthConfigurer.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,39 @@ public static void Configure(IServiceCollection services, IConfiguration configu
1616
{
1717
if (bool.Parse(configuration["Authentication:JwtBearer:IsEnabled"]))
1818
{
19-
services.AddAuthentication()
20-
.AddJwtBearer(options =>
21-
{
22-
options.Audience = configuration["Authentication:JwtBearer:Audience"];
19+
services.AddAuthentication(options => {
20+
options.DefaultAuthenticateScheme = "JwtBearer";
21+
options.DefaultChallengeScheme = "JwtBearer";
22+
}).AddJwtBearer("JwtBearer", options =>
23+
{
24+
options.Audience = configuration["Authentication:JwtBearer:Audience"];
2325

24-
options.TokenValidationParameters = new TokenValidationParameters
25-
{
26-
// The signing key must match!
27-
ValidateIssuerSigningKey = true,
28-
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(configuration["Authentication:JwtBearer:SecurityKey"])),
26+
options.TokenValidationParameters = new TokenValidationParameters
27+
{
28+
// The signing key must match!
29+
ValidateIssuerSigningKey = true,
30+
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(configuration["Authentication:JwtBearer:SecurityKey"])),
2931

30-
// Validate the JWT Issuer (iss) claim
31-
ValidateIssuer = true,
32-
ValidIssuer = configuration["Authentication:JwtBearer:Issuer"],
32+
// Validate the JWT Issuer (iss) claim
33+
ValidateIssuer = true,
34+
ValidIssuer = configuration["Authentication:JwtBearer:Issuer"],
3335

34-
// Validate the JWT Audience (aud) claim
35-
ValidateAudience = true,
36-
ValidAudience = configuration["Authentication:JwtBearer:Audience"],
36+
// Validate the JWT Audience (aud) claim
37+
ValidateAudience = true,
38+
ValidAudience = configuration["Authentication:JwtBearer:Audience"],
3739

38-
// Validate the token expiry
39-
ValidateLifetime = true,
40+
// Validate the token expiry
41+
ValidateLifetime = true,
4042

41-
// If you want to allow a certain amount of clock drift, set that here
42-
ClockSkew = TimeSpan.Zero
43-
};
43+
// If you want to allow a certain amount of clock drift, set that here
44+
ClockSkew = TimeSpan.Zero
45+
};
4446

45-
options.Events = new JwtBearerEvents
46-
{
47-
OnMessageReceived = QueryStringTokenResolver
48-
};
49-
});
47+
options.Events = new JwtBearerEvents
48+
{
49+
OnMessageReceived = QueryStringTokenResolver
50+
};
51+
});
5052
}
5153
}
5254

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Host/Startup/Startup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
106106

107107
app.UseAuthentication();
108108

109-
app.UseJwtTokenMiddleware();
110-
111109
app.UseAbpRequestLocalization();
112110

113111
#if FEATURE_SIGNALR

0 commit comments

Comments
 (0)