-
Notifications
You must be signed in to change notification settings - Fork 139
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
Best way to authenticate requests #17
Comments
I had a similar problem, but I basically implemented a workaround such that a user could access the graphqlview only on the testing/development environment (localhost). Depends on what your goal is, I only had the graphqlview to help me model and test graphql queries, and didn't actually want it available in the production environment. Here's the code if you're interested:
|
@kmakihara Did you end up writing individual graphql routes that handle authentication? How are you limiting the amount of data an authenticated user can potentially receive without limiting the usefulness of graphql? |
It's been a while that issue is open, but for general purpose, I ended up using route decorators in my view function like this :
Here I use a JWT authentication with but I could use flask-login or any authentication method:
|
Here is maybe a more intuitive way for those who don't use jwt:
|
Taking the suggestions above, I have been able to use existing Python JWT libraries to authenticate the UPDATE: |
I am using flask + jwt.
For mutations I have to create abstract mutation class and extend it with all my mutation except login mutation:
All credentials and tokes related work is handeled by Hope it will be helpful. |
Hi, I'm the maintainer of Flask-GraphQL-Auth. Inspired by Flask-JWT-Extended, There is a problem with error-handling but it works pretty well. How about try this? You can use Flask-GraphQL-Auth like you used Flask-JWT-Extended. here are some examples. class Query(graphene.ObjectType):
protected = graphene.String(message=graphene.String(),
token=graphene.String())
@query_jwt_required
def resolve_protected(self, info, message):
return str(get_raw_jwt()) you can find more on github and docs GitHub: https://github.com/callsign-viper/Flask-GraphQL-Auth |
I am trying to figure out the best way to authenticate a request before my schema executes the query/mutation. I was thinking I could use the @app.resolver('url') tag and create a function that would authenticate the request and then pass it to the graphqlview. Something like this:
But this doesn't work, can someone either show me what I am doing wrong here or give me a different way to authenticate the request? Thanks!
The text was updated successfully, but these errors were encountered: