@@ -41,6 +41,29 @@ public static IServiceCollection AddJwtAuthentication(this IServiceCollection se
41
41
var bearerOptions = new JwtAuthenticationOptions ( ) ;
42
42
optionsAction ? . Invoke ( bearerOptions ) ;
43
43
44
+ return services . AddJwtAuthentication ( bearerOptions ) ;
45
+ }
46
+
47
+ /// <summary>
48
+ ///
49
+ /// </summary>
50
+ /// <param name="services"></param>
51
+ /// <param name="configurationSectionName"></param>
52
+ /// <returns></returns>
53
+ public static IServiceCollection AddJwtAuthentication ( this IServiceCollection services , string configurationSectionName )
54
+ {
55
+ var bearerOptions = services . GetConfiguration ( ) . GetSection ( configurationSectionName ) . Get < JwtAuthenticationOptions > ( ) ;
56
+ return services . AddJwtAuthentication ( bearerOptions ) ;
57
+ }
58
+
59
+ /// <summary>
60
+ /// Adds Jwt authentication to the DI container.
61
+ /// </summary>
62
+ /// <param name="services"></param>
63
+ /// <param name="bearerOptions"></param>
64
+ /// <returns></returns>
65
+ public static IServiceCollection AddJwtAuthentication ( this IServiceCollection services , JwtAuthenticationOptions bearerOptions )
66
+ {
44
67
JwtSecurityTokenHandler . DefaultInboundClaimTypeMap . Clear ( ) ;
45
68
46
69
var key = Encoding . UTF8 . GetBytes ( bearerOptions . SigningKey ) ;
@@ -107,33 +130,14 @@ public static IServiceCollection AddJwtAuthentication(this IServiceCollection se
107
130
RoleClaimType = JwtClaimTypes . Role ,
108
131
ValidIssuers = bearerOptions . Issuer ,
109
132
//ValidAudience = "api",
110
- ValidateIssuer = false ,
111
- ValidateAudience = false ,
133
+ ValidateIssuer = bearerOptions . ValidateIssuer ,
134
+ ValidateAudience = bearerOptions . ValidateAudience ,
112
135
IssuerSigningKey = new SymmetricSecurityKey ( key )
113
136
} ;
114
137
} ) ;
115
138
return services ;
116
139
}
117
140
118
- /// <summary>
119
- ///
120
- /// </summary>
121
- /// <param name="services"></param>
122
- /// <param name="configurationSectionName"></param>
123
- /// <returns></returns>
124
- public static IServiceCollection AddJwtAuthentication ( this IServiceCollection services , string configurationSectionName )
125
- {
126
- var bearerOptions = services . GetConfiguration ( ) . GetSection ( configurationSectionName ) . Get < JwtAuthenticationOptions > ( ) ;
127
- return services . AddJwtAuthentication ( options =>
128
- {
129
- options . Audience = bearerOptions . Audience ;
130
- options . Authority = bearerOptions . Authority ;
131
- options . Issuer = bearerOptions . Issuer ;
132
- options . RequireHttpsMetadata = bearerOptions . RequireHttpsMetadata ;
133
- options . SigningKey = bearerOptions . SigningKey ;
134
- } ) ;
135
- }
136
-
137
141
/// <summary>
138
142
///
139
143
/// </summary>
0 commit comments