@@ -16,37 +16,39 @@ public static void Configure(IServiceCollection services, IConfiguration configu
16
16
{
17
17
if ( bool . Parse ( configuration [ "Authentication:JwtBearer:IsEnabled" ] ) )
18
18
{
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" ] ;
23
25
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" ] ) ) ,
29
31
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" ] ,
33
35
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" ] ,
37
39
38
- // Validate the token expiry
39
- ValidateLifetime = true ,
40
+ // Validate the token expiry
41
+ ValidateLifetime = true ,
40
42
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
+ } ;
44
46
45
- options . Events = new JwtBearerEvents
46
- {
47
- OnMessageReceived = QueryStringTokenResolver
48
- } ;
49
- } ) ;
47
+ options . Events = new JwtBearerEvents
48
+ {
49
+ OnMessageReceived = QueryStringTokenResolver
50
+ } ;
51
+ } ) ;
50
52
}
51
53
}
52
54
0 commit comments