File tree Expand file tree Collapse file tree
Sources/EasyExtensions.AspNetCore.Authorization/Extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ public static class ServiceCollectionExtensions
3131 /// Reads settings from JwtSettings section or flat fallback Jwt[Key] configuration values (see <see cref="ConfigurationExtensions.GetJwtSettings"/>).
3232 /// </summary>
3333 /// <param name="services"><see cref="IServiceCollection"/> instance.</param>
34+ /// <param name="useCookies">If <c>true</c>, JWT token will be read from cookies (if not found in query string).</param>
3435 /// <returns>Current <see cref="IServiceCollection"/> instance.</returns>
3536 /// <exception cref="KeyNotFoundException">When required JWT settings are missing.</exception>
3637 /// <remarks>
@@ -67,7 +68,7 @@ public static class ServiceCollectionExtensions
6768 /// <item><description><c>RequireHttpsMetadata = false</c> (adjust in production if needed).</description></item>
6869 /// </list>
6970 /// </remarks>
70- public static IServiceCollection AddJwt ( this IServiceCollection services )
71+ public static IServiceCollection AddJwt ( this IServiceCollection services , bool useCookies = false )
7172 {
7273 services . AddScoped < ITokenProvider , JwtTokenProvider > ( ) ;
7374 services . AddAuthentication ( JwtBearerDefaults . AuthenticationScheme )
@@ -102,7 +103,7 @@ public static IServiceCollection AddJwt(this IServiceCollection services)
102103 {
103104 context . Token = accessToken ;
104105 }
105- if ( string . IsNullOrWhiteSpace ( context . Token ) )
106+ else if ( useCookies && string . IsNullOrWhiteSpace ( context . Token ) )
106107 {
107108 string ? cookieToken = context . Request . Cookies [ AccessTokenParamName ] ;
108109 if ( ! string . IsNullOrEmpty ( cookieToken ) )
You can’t perform that action at this time.
0 commit comments