Skip to content
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

Merged
merged 34 commits into from
Jan 5, 2021

Conversation

rose-a
Copy link
Contributor

@rose-a rose-a commented Dec 26, 2020

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 custom IErrorInfoProvider as suggested here by @Shane32.

What's needed for this do be ready to merge?

}
// 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.
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@rose-a rose-a Jan 4, 2021

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

Copy link
Member

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.

@sungam3r sungam3r added the enhancement New feature or request label Dec 26, 2020
@sungam3r
Copy link
Member

I will review this tomorrow. Thanks.

@sungam3r
Copy link
Member

sungam3r commented Jan 4, 2021

It would be nice to put example of this #478 (comment) into samples.

@sungam3r sungam3r added the new API New non breaking public APIs added label Jan 4, 2021
@sungam3r
Copy link
Member

sungam3r commented Jan 4, 2021

I pushed CodeQL analysis action along with dotnet-format checks into develop.

@rose-a rose-a requested a review from sungam3r January 4, 2021 14:34
@sungam3r
Copy link
Member

sungam3r commented Jan 4, 2021

samples/Samples.Server/Startup.cs(2,1): Using directive is unnecessary. (IDE0005)

@sungam3r sungam3r requested a review from Shane32 January 4, 2021 16:36
@rose-a rose-a requested a review from sungam3r January 5, 2021 07:15
Copy link
Member

@sungam3r sungam3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally!

@sungam3r sungam3r merged commit 2b55ad7 into graphql-dotnet:develop Jan 5, 2021
@rose-a
Copy link
Contributor Author

rose-a commented Jan 6, 2021

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new API New non breaking public APIs added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants