-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Selectively allow anonymous access #44
Comments
Currently u could also just do it like .AuthorizeWith(""); or some other non existing policy name. If the policy doesnt exists the user is also authorized. |
@Fireblade954 that is no longer allowed with this issue fixed (PR merged) #15 Thank you for the suggestion |
Easiest way I found to-do with was: (at whatever levels you need)
Usage sample here: But this one of those - roll it like you need it cases. |
I think the issue of using the policies found in the GraphQL document is much broader and in some way relates to #6. Now I see the problem that it's not just enought to make auth check immediately when walking over AST. There should be some new component that accumulates all found policies to apply and then ... do something with them. In your case this component should filter policies to allow some priority model. In other cases it can modify/add policies, I don't know exactly. Such a view will allow not to mix different tasks in a bunch. One task - find all appliable checks with theirs context from input document. Another task - use somehow that information before performing checks. Ping @joemcbride @Shane32 . |
In other words, the need to fulfill the defined policies depends on the state of the entire AST. |
Or how do you like this solution - allow to remove validation errors from |
I think this is the main thing. |
I’m not sure I understand exactly what you suggested @sungam3r . I would comment on the original issue/suggestion, and say I agree, but I’m not exactly sure how. I think of ASP.Net where you can specify AllowAnonymous to make a specific action accessible regardless of the authentication attribute on the parent. For GraphQL.NET it would be nice if all those conditions are precomputed when the schema is built to save on execution time at runtime. |
Yesterday I reflected a lot about possible ways to implement. All decisions coming to the head, one way or another were associated with difficulties. Difficulties not only technical details, but also design. As a result, I came to the conclusion, which seems to me the easiest solution to the problem - no need to invent any sophisticated ways to override policies. The easiest, understandable and least erroneous way is to develop your schema in accordance with the required policies: type Query {
public: PublicApi! no authorization here
authorized : AuthorizedApi! authorized with some requirements
}
type PublicApi {
login(input: LoginInput!): LoginResult!
help(message: String!): FeedbackResult!
otherPublicFields: ...
}
type AuthorizedApi {
author(input: AuthorInputType!): String,
otherFields: ...
} These are so called namespace-types or role-types. Another example: query {
viewer {
getNews
getAds
}
me {
nickname
photo
}
admin {
shutdown
exposePersonalData
}
} In this case, several qualities are achieved at once:
I could speculate some time about how to change the mechanism of policies checks, but I strongly doubt that this will lead to a decent solution. |
@dnndevelopernc I close this for now. Reopen if you have further questions. |
@sungam3r I don’t think we should close this issue. Redesigning the schema isn’t typically an acceptable solution for most users. The feature request isn’t unreasonable and is probably a good idea. |
Any update on this? |
The authorization validation rule included with GraphQL.Server supports AllowAnonymous, effectively white listing a specific field within a graph type. There are other differences so be sure to read the documentation within the GraphQL.Server readme. I don’t believe this repo has been updated to support AllowAnonymous. |
Is it possible to white list one or more endpoints?
for example: I would like to require authentication for all mutation and queries except for Login.
Currently we authorize each mutation individually - we fear forgetting one will ship and endpoint with open access. The query mutation we AuthorizeWith at the root level therefore it catches all endpoints.
If this is not possible with the current implementation, I am happy to create a PR but how would this work? Instead of AuthorizeWith on an endpoint have DisableAuthorization() ? This could add metadata that is inspected during evaluation to bypass root level policies. What are the drawbacks to this approach?
Update
Took the initial approach of removing operation level validation and the fields now inherit parent policies if they are not flagged a public.
Example
The text was updated successfully, but these errors were encountered: