@@ -43,6 +43,7 @@ namespace Intersect.Server.Web;
4343
4444internal partial class ApiService : ApplicationService < ServerContext , IApiService , ApiService > , IApiService
4545{
46+ private const string BearerCookieFallbackAuthenticationScheme = "BearerCookieFallback" ;
4647 private WebApplication ? _app ;
4748 private static readonly Assembly Assembly = typeof ( ApiService ) . Assembly ;
4849
@@ -153,14 +154,7 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
153154
154155 builder . Services . AddSingleton < IntersectAuthenticationManager > ( ) ;
155156
156- builder . Services . AddAuthentication (
157- options =>
158- {
159- options . DefaultAuthenticateScheme = CookieAuthenticationDefaults . AuthenticationScheme ;
160- options . DefaultChallengeScheme = JwtBearerDefaults . AuthenticationScheme ;
161- options . DefaultScheme = CookieAuthenticationDefaults . AuthenticationScheme ;
162- }
163- )
157+ builder . Services . AddAuthentication ( BearerCookieFallbackAuthenticationScheme )
164158 . AddCookie (
165159 CookieAuthenticationDefaults . AuthenticationScheme ,
166160 options =>
@@ -288,6 +282,15 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
288282 SymmetricSecurityKey issuerKey = new ( tokenGenerationOptions . SecretData ) ;
289283 options . TokenValidationParameters . IssuerSigningKey = issuerKey ;
290284 }
285+ ) . AddPolicyScheme (
286+ BearerCookieFallbackAuthenticationScheme ,
287+ "Bearer-to-Cookie Fallback" ,
288+ pso =>
289+ {
290+ pso . ForwardDefaultSelector = context => context . Request . Headers . Authorization . Count > 0
291+ ? JwtBearerDefaults . AuthenticationScheme
292+ : CookieAuthenticationDefaults . AuthenticationScheme ;
293+ }
291294 ) ;
292295
293296 builder . Services . AddOutputCache ( o => o . AddPolicy ( nameof ( AvatarController ) , AvatarController . OutputCachePolicy ) ) ;
0 commit comments