-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Allow more failure details for AuthZ handlers #35319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
New Overload Fail on
+public class AuthorizationFailureReason
{
+ Encapsulates a reason why authorization failed
+ public AuthorizationFailureReason(IAuthorizationHandler handler, string message)
+ public string Message { get; set; }
+ public IAuthorizationHandler Handler { get; set; } public class AuthorizationHandlerContext
{
+ // Calls Fail() and stores the failure state for future reference. Can be called multiple times.
+ public virtual void Fail(AuthorizationFailureReason);
+ public IEnumerable<AuthorizationFailureReason> FailureReasons { get; } The IAuthorizationEvaluator checks for failure and bundles it into an AuthorizationFailure aspnetcore/src/Security/Authorization/Core/src/DefaultAuthorizationEvaluator.cs Lines 19 to 20 in 8b30d86
public class AuthorizationFailure
{
+ // Calls Fail and stores the failure reasons for future reference. Can be called multiple times.
+ public static void ExplicitFail(IEnumerable<AuthorizationFailureReason> reasons);
+ public IEnumerable<AuthorizationFailureReason> FailureStates { get; } Which ends up on the AuthorizationResult:
Which is then passed to the IAuthorizationMiddlewareResultHandler aspnetcore/src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs Lines 105 to 107 in 302ed3c
aspnetcore/src/Security/Authorization/Policy/src/IAuthorizationMiddlewareResultHandler.cs Line 24 in 302ed3c
Full PR: #35425 |
I don't think it necessarily makes sense to force correlation of requirements/reasons, but we could do Handler -> reasons, since that is really the split, but the failure state should be the mechanism to communicate information, if the handler wants to enumerate the requirements that failed, they are free to put that in the failure reason explicitly, but that mapping is completely up to the app/handlers |
State has multiple meanings, I'd prefer reasons. But object feels, odd to me. I'd suggest an interface here with, at least, a message property, so folks don't have to cast around if they don't want to? As an aside aren't there old issues about this? We should link them. |
Isn't the argument against interfaces future breaking change concerns? We could do a base FailureReason class which has a message property? |
Did this get API reviewed? |
Oops, no I'll add the labels |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
1 similar comment
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
public class AuthorizationFailureReason
{
+ public AuthorizationFailureReason(IAuthorizationHandler handler, string message)
+ public string Message { get; }
+ public IAuthorizationHandler Handler { get; }
}
API consideration: Can this type be sealed and use a `IDictionary` to pass additional data instead e.g.
```diff
+public sealed class AuthorizationFailureReason
{
+ public AuthorizationFailureReason(IAuthorizationHandler handler, string message)
+ public string Message { get; }
+ public IAuthorizationHandler Handler { get; }
+ public IDictionary<object, object> Properties { get; }
} AuthorizationFailure
public class AuthorizationFailure
{
+ // Calls Fail and stores the failure reasons for future reference. Can be called multiple times.
+ public static void ExplicitFail(IEnumerable<AuthorizationFailureReason> reasons);
+ public IEnumerable<AuthorizationFailureReason> FailureReasons { get; } |
@blowdart / @adityamandaleeka is someone on point to update the PR based on the API feedback? |
If hao isn't here @Tratcher i'd guess |
@pranavkm I'm interested in doing this. May I send the PR? |
We'd appreciate that @Kahbazi. Thanks! |
A) There's an RC1 PR here that needs updating: #35529. @Kahbazi you'll need to send a PR to that branch.
@blowdart? When designing this we specifically discussed an unsealed type that could be derived from to add strongly typed data. Using a loosely typed dictionary didn't come up. Either way requires downcasting, though with the derived type it would only be a single downcast instead of per property. |
A single cast seems the better approach, less error prone and faster. |
This is outdated, the name used in the PR is:
|
Are we sure we want |
Today there's no way to signal anything other than which requirements have failed or an explicit Fail https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authorization/Core/src/AuthorizationHandlerContext.cs#L82
This makes it hard for a handler to flow more specific error information/details to the
IAuthorizationMiddlewareResultHandler
The text was updated successfully, but these errors were encountered: