Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

ForbidAsync now uses correct Schemes method #918

Merged
merged 3 commits into from
Aug 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public virtual async Task ForbidAsync(HttpContext context, string scheme, Authen
{
if (scheme == null)
{
var defaultChallengeScheme = await Schemes.GetDefaultChallengeSchemeAsync();
scheme = defaultChallengeScheme?.Name;
var defaultForbidScheme = await Schemes.GetDefaultForbidSchemeAsync();
scheme = defaultForbidScheme?.Name;
if (scheme == null)
{
throw new InvalidOperationException($"No authenticationScheme was specified, and there was no DefaultChallengeScheme found.");
throw new InvalidOperationException($"No authenticationScheme was specified, and there was no DefaultForbidScheme found.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public async Task ServicesWithDefaultSignOutMethodsTest()
await Assert.ThrowsAsync<InvalidOperationException>(() => context.SignInAsync(new ClaimsPrincipal()));
}

[Fact]
public async Task ServicesWithDefaultForbidMethod_CallsForbidMethod()
{
var services = new ServiceCollection().AddOptions().AddAuthenticationCore(o =>
{
o.AddScheme<ForbidHandler>("forbid", "whatever");
o.DefaultForbidScheme = "forbid";
}).BuildServiceProvider();
var context = new DefaultHttpContext();
context.RequestServices = services;

await context.ForbidAsync();
}


private class BaseHandler : IAuthenticationHandler
{
Expand Down Expand Up @@ -245,5 +259,43 @@ public Task SignOutAsync(AuthenticationProperties properties)
}
}

private class ForbidHandler : IAuthenticationHandler, IAuthenticationRequestHandler, IAuthenticationSignInHandler, IAuthenticationSignOutHandler
{
public Task<AuthenticateResult> AuthenticateAsync()
{
throw new NotImplementedException();
}

public Task ChallengeAsync(AuthenticationProperties properties)
{
throw new NotImplementedException();
}

public Task ForbidAsync(AuthenticationProperties properties)
{
return Task.FromResult(0);
}

public Task<bool> HandleRequestAsync()
{
throw new NotImplementedException();
}

public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context)
{
return Task.FromResult(0);
}

public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties)
{
throw new NotImplementedException();
}

public Task SignOutAsync(AuthenticationProperties properties)
{
throw new NotImplementedException();
}
}

}
}