-
Notifications
You must be signed in to change notification settings - Fork 592
Add AccessDeniedPath support to the OIDC/OAuth2/Twitter providers #1887
Changes from all commits
c1b19d6
3db120d
e03fc3e
0afe7f1
f2a9f0b
fd5bc2c
b5bf034
8c6a456
5fcbb1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,7 +186,7 @@ public async virtual Task SignOutAsync(AuthenticationProperties properties) | |
properties.RedirectUri = BuildRedirectUriIfRelative(Options.SignedOutRedirectUri); | ||
if (string.IsNullOrWhiteSpace(properties.RedirectUri)) | ||
{ | ||
properties.RedirectUri = CurrentUri; | ||
properties.RedirectUri = OriginalPathBase + OriginalPath + Request.QueryString; | ||
} | ||
} | ||
Logger.PostSignOutRedirect(properties.RedirectUri); | ||
|
@@ -312,7 +312,7 @@ protected override async Task HandleChallengeAsync(AuthenticationProperties prop | |
// 2. CurrentUri if RedirectUri is not set) | ||
if (string.IsNullOrEmpty(properties.RedirectUri)) | ||
{ | ||
properties.RedirectUri = CurrentUri; | ||
properties.RedirectUri = OriginalPathBase + OriginalPath + Request.QueryString; | ||
} | ||
Logger.PostAuthenticationLocalRedirect(properties.RedirectUri); | ||
|
||
|
@@ -520,6 +520,16 @@ protected override async Task<HandleRequestResult> HandleRemoteAuthenticateAsync | |
// if any of the error fields are set, throw error null | ||
if (!string.IsNullOrEmpty(authorizationResponse.Error)) | ||
{ | ||
// Note: access_denied errors are special protocol errors indicating the user didn't | ||
kevinchalet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// approve the authorization demand requested by the remote authorization server. | ||
// Since it's a frequent scenario (that is not caused by incorrect configuration), | ||
// denied errors are handled differently using HandleAccessDeniedErrorAsync(). | ||
// Visit https://tools.ietf.org/html/rfc6749#section-4.1.2.1 for more information. | ||
if (string.Equals(authorizationResponse.Error, "access_denied", StringComparison.Ordinal)) | ||
{ | ||
return await HandleAccessDeniedErrorAsync(properties); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Tratcher pretty much like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no other parameters in the message we'd be missing out on, right? The most awkward bit seems to be having to downcast the Options if you wanted anything specific. Or could you flow the generic TOptions? I remember trying that and having lots of issues before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We could update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see those being useful if properly populated. It seems like you'd want to flow a generic property bag to the event rather than hardcoded parameters. I guess you could pass them through AuthProperties or some HttpContext field if you really needed to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep.
We can certainly do that, but I'm a bit reluctant as it would be fairly inconsistent (we don't do that anywhere else). |
||
} | ||
|
||
return HandleRequestResult.Fail(CreateOpenIdConnectProtocolException(authorizationResponse, response: null), properties); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Microsoft.AspNetCore.Authentication | ||
{ | ||
/// <summary> | ||
/// Provides access denied failure context information to handler providers. | ||
/// </summary> | ||
public class AccessDeniedContext : HandleRequestContext<RemoteAuthenticationOptions> | ||
{ | ||
public AccessDeniedContext( | ||
HttpContext context, | ||
AuthenticationScheme scheme, | ||
RemoteAuthenticationOptions options) | ||
: base(context, scheme, options) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the endpoint path the user agent will be redirected to. | ||
/// By default, this property is set to <see cref="RemoteAuthenticationOptions.AccessDeniedPath"/>. | ||
/// </summary> | ||
public PathString AccessDeniedPath { get; set; } | ||
|
||
/// <summary> | ||
/// Additional state values for the authentication session. | ||
/// </summary> | ||
public AuthenticationProperties Properties { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the return URL that will be flowed up to the access denied page. | ||
/// If <see cref="ReturnUrlParameter"/> is not set, this property is not used. | ||
/// </summary> | ||
public string ReturnUrl { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the parameter name that will be used to flow the return URL. | ||
/// By default, this property is set to <see cref="RemoteAuthenticationOptions.ReturnUrlParameter"/>. | ||
/// </summary> | ||
public string ReturnUrlParameter { get; set; } | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.