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

Pass authentication through root resolver instead of middleware? #1415

Open
chainlink opened this issue Dec 11, 2020 · 4 comments
Open

Pass authentication through root resolver instead of middleware? #1415

chainlink opened this issue Dec 11, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@chainlink
Copy link

Hi there,
Is is possible to pass authentication via &graph.Resolver{} instead of through context? Having Auth in middleware/context tightly couples it to the implementation (and requires all tests, etc to be blessed with the right context) As well, it would be nice to be able to use the graphql error presenter for eveything including auth, instead of bailing out early in middleware

To do this, I think I need to generate the schema per request, but I'm not sure of the performance penalty here

@Ekliptor
Copy link

I am also interested in this question. Especially since it would also make it easier to manage different GraphQL queries which require different user permissions.

Any examples on how to to this?

@philipjscott
Copy link

Isn't doing auth through the GraphQL layer impossible in certain cases? (e.g. cookie-based authentication)

https://github.com/99designs/gqlgen/blob/master/docs/content/recipes/authentication.md

Because GraphQL is transport agnostic we can't assume there will even be an HTTP request, so we need to expose these authentication details to our graph using a middleware.

@chainlink
Copy link
Author

I'm happy if it's not built into gqlgen, but would be nice to have a path for it for folks that would like it.

@philipjscott
Copy link

I suppose, but the question is whether it's even possible for some users. Suppose you're sending an authorization token through a cookie, how will you be able to access it in the root resolver? Since GraphQL is supposed to support both websocket and "normal" HTTP requests, it'll definitely complicate the resolver API to add this functionality.

Of course, there are definitely pros; I wonder what the maintainers think.

@frederikhors frederikhors added the enhancement New feature or request label Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants