@@ -327,7 +327,6 @@ protected virtual Task HandleSignOutAsync(SignOutContext context)
327327 /// Override this method to deal with a challenge that is forbidden.
328328 /// </summary>
329329 /// <param name="context"></param>
330- /// <returns>The returned boolean is ignored.</returns>
331330 protected virtual Task < bool > HandleForbiddenAsync ( ChallengeContext context )
332331 {
333332 Response . StatusCode = 403 ;
@@ -340,7 +339,7 @@ protected virtual Task<bool> HandleForbiddenAsync(ChallengeContext context)
340339 /// changing the 401 result to 302 of a login page or external sign-in location.)
341340 /// </summary>
342341 /// <param name="context"></param>
343- /// <returns>The returned boolean is no longer used. </returns>
342+ /// <returns>True if no other handlers should be called </returns>
344343 protected virtual Task < bool > HandleUnauthorizedAsync ( ChallengeContext context )
345344 {
346345 Response . StatusCode = 401 ;
@@ -350,6 +349,7 @@ protected virtual Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
350349 public async Task ChallengeAsync ( ChallengeContext context )
351350 {
352351 ChallengeCalled = true ;
352+ var handled = false ;
353353 if ( ShouldHandleScheme ( context . AuthenticationScheme , Options . AutomaticChallenge ) )
354354 {
355355 switch ( context . Behavior )
@@ -363,18 +363,18 @@ public async Task ChallengeAsync(ChallengeContext context)
363363 }
364364 goto case ChallengeBehavior . Unauthorized ;
365365 case ChallengeBehavior . Unauthorized :
366- await HandleUnauthorizedAsync ( context ) ;
366+ handled = await HandleUnauthorizedAsync ( context ) ;
367367 Logger . AuthenticationSchemeChallenged ( Options . AuthenticationScheme ) ;
368368 break ;
369369 case ChallengeBehavior . Forbidden :
370- await HandleForbiddenAsync ( context ) ;
370+ handled = await HandleForbiddenAsync ( context ) ;
371371 Logger . AuthenticationSchemeForbidden ( Options . AuthenticationScheme ) ;
372372 break ;
373373 }
374374 context . Accept ( ) ;
375375 }
376376
377- if ( PriorHandler != null )
377+ if ( ! handled && PriorHandler != null )
378378 {
379379 await PriorHandler . ChallengeAsync ( context ) ;
380380 }
0 commit comments