-
Notifications
You must be signed in to change notification settings - Fork 164
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
Add AuthorizationError (pickup of #479) #480
Add AuthorizationError (pickup of #479) #480
Conversation
} | ||
// TODO: check to see if only a single failure result is returned in result.Failure.FailedRequirements, | ||
// and report a single specific error class for that result. fall back to the below when multiple | ||
// errors are reported. or instead of the fallback, report separate error instances for each entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As already expressed in #478 I'm opposed to generating a separate error for each failed requirement. It would result in many lines starting with "You are not authorized to run this [operation] because ...", and IMO failure to authorize should be a single validation error.
Any opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinion. Feel free to delete the comment if that is the consensus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rose-a See graphql-dotnet/authorization#117
It is also unnecessarily complex to query for the error code in the json, since it is an array of errors and in one query there could be errors relating to something other than authentication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any opinions?
I'm 50/50 but I'm OK to merge PR as is since AddValidationError
is virtual now and one can override it to make multiple calls to context.ReportError
with customized messages. Moreover then actual messages written in response could be customized in custom IErrorInfoProvider
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For graphql-dotnet/authorization#117 they would have to override GraphQLHttpMiddleware to create a 401 status code on an AuthorizationError
containing a DenyAnonymousAuthorizationRequirement
as failed requirement... This PR only lays the foundations for this, currently it is not possible to change the status code of the HTTP response based on GraphQL execution errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. Thanks. FYI @tobias-tengler.
I will review this tomorrow. Thanks. |
It would be nice to put example of this #478 (comment) into samples. |
I pushed CodeQL analysis action along with dotnet-format checks into |
samples/Samples.Server/Startup.cs(2,1): Using directive is unnecessary. (IDE0005) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally!
👍 |
I picked up #479 and rebased it to the current
develop
branch. It currently is a "non-breaking" change which opens up the possibility to generate custom error messages by injecting a customIErrorInfoProvider
as suggested here by @Shane32.What's needed for this do be ready to merge?