@@ -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
0 commit comments