-
-
Notifications
You must be signed in to change notification settings - Fork 936
Add AllowAnonymous extension method and attribute #3079
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
Conversation
`Authorize` can be used to specify that only authentication is required, without specifying any specific roles or policies. | ||
As with `AuthorizeWithPolicy` (renamed from `AuthorizeWith`), it requires support by a third-party | ||
library to perform the validation. | ||
`AllowAnonymous` indicates that anonymous access should be allowed to a field of a graph type requiring authorization, |
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 suggest not to narrow meaning of allowanonymous only to fields like for actions in ASP.NET controllers. It's GraphQL world.
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.
In this case, I'm not really thinking about how it relates to ASP.NET (apart from the naming and general concept), but rather the practical usage of this attribute in the GraphQL world. I'm just not sure how AllowAnonymous would be useful to apply to a graph, since graphs are generally abstract from other graphs. For instance, if Product is marked as AllowAnonymous, and if MasterProductsTable is protected, querying for all products within MasterProductsTable should still be refused. The same thought process applies to input object graphs and scalars, leaving only fields at this time.
Within ASP.NET Core, only one action can ever execute, so AllowAnonymous simply overrides all Authorize attributes that are parent to it in the chain. In this respect, my suggestion is unlike ASP.NET Core. It's simply what works best for GraphQL.
I can remove the attribute usage restriction, but even if we did so, I figured that the xml comments should explain anticipated usage of the attributes, even knowing that implementation is not part of this library. If nothing else, use the word "typically" and retain the wording/example.
Do you suggest I remove the attribute usage restrictions? Do you have a suggestion of rewording here?
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.
implementation is not part of this library
This is true and we must leave some space for maneuver.
word "typically" and retain the wording/example
Yes, let's insert typically somewhere. The general meaning will be the same, but the phrase will sound more accurate.
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.
`AllowAnonymous` indicates that anonymous access should be allowed to a field of a graph type requiring authorization, | |
`AllowAnonymous` typically indicates that anonymous access should be allowed to a field of a graph type requiring authorization, |
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.
See above (merged).
Co-authored-by: Ivan Maximov <[email protected]>
@sungam3r I'm working on an authorization implementation that works with all the PRs over the last couple days. One question that is interesting to consider is: Should the introspection field types be marked with Consider these queries: # this query requires authentication because ProtectedType requires authentication
{
protectedType { # the type, not the field here, is marked as needing authentication
unmarkedField
anonymousField
}
}
# this query does not require authentication becauase although ProtectedType requires
# authentication, all of the selected fields are marked with AllowAnonymous
{
protectedType {
anonymousField
}
}
# this query also does not require authentication
{
protectedType {
__typeName
anonymousField
}
}
# this query SHOULD require authentication, because it could unintentionally reveal information to the caller,
# if for example the schema designer did not mark any fields with AllowAnonymous
{
protectedType {
__typeName
}
} So as you can see, in my implementation Now for |
p.s. Dealing with fragments and the |
Codecov Report
@@ Coverage Diff @@
## master #3079 +/- ##
=======================================
Coverage 84.38% 84.38%
=======================================
Files 360 361 +1
Lines 15830 15842 +12
Branches 2576 2576
=======================================
+ Hits 13358 13369 +11
- Misses 1858 1859 +1
Partials 614 614
Continue to review full report at Codecov.
|
:) I was biten by that when doing complexity analizer. Regarding all other notes. Yes, auth validation is a pain. There are so much questions to think about. I have already thought about them, because in my work we use an extensive system for checking auth directives. I came to the conclusion that there is no ideal solution. Implementation can pursue different purposes. Also remember of graphql-dotnet/authorization#186 (abandoned). |
@sungam3r I am going to finish my auth code tonight, add a million tests and all that stuff, and make sure it is operating as I am anticipating that it should. I know you're wrapping up for the night, but by your morning, you'll be able to see my progress in Shane32/GraphQL.AspNetCore3#6 . (Don't look now, it's not nearly finished.) I will plan to release 5.1.1 in the morning; just reply if you have any comments or objections between now and then. |
If you would like to help review my implementation, particularly the public API, let me know. I know you are busy and also support a lot of open-source projects, so if you don't have time, that's fine too. |
@sungam3r I'm going to release 5.1.1 now. |
OK. I opened your PR. Now the main thing is not to lose it among the other 150 open tabs. |
Closes #3078
For 5.1.1