Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit e609cda

Browse files
committed
#1044 Revert "Auth: Always call prior handlers during Challenge"
This reverts commit e12838e.
1 parent 673df3e commit e609cda

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

test/Microsoft.AspNetCore.Authentication.Test/AuthenticationHandlerFacts.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ public async Task AuthHandlerAuthenticateCachesTicket(string scheme)
7575
Assert.Equal(1, handler.AuthCount);
7676
}
7777

78-
// Prior to https://github.com/aspnet/Security/issues/930 we wouldn't call prior if handled
79-
[Fact]
80-
public async Task AuthHandlerChallengeAlwaysCallsPriorHandler()
78+
[Theory]
79+
[InlineData("Alpha", false)]
80+
[InlineData("Bravo", true)]
81+
public async Task AuthHandlerChallengeCallsPriorHandlerIfNotHandled(string challenge, bool passedThrough)
8182
{
8283
var handler = await TestHandler.Create("Alpha");
8384
var previous = new PreviousHandler();
8485

8586
handler.PriorHandler = previous;
86-
await handler.ChallengeAsync(new ChallengeContext("Alpha"));
87-
Assert.True(previous.ChallengeCalled);
87+
await handler.ChallengeAsync(new ChallengeContext(challenge));
88+
Assert.Equal(passedThrough, previous.ChallengeCalled);
8889
}
8990

9091
private class PreviousHandler : IAuthenticationHandler

0 commit comments

Comments
 (0)