-
Notifications
You must be signed in to change notification settings - Fork 764
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Bypass csrf #61
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
Comments
Hi @nlhkh! You can do something like: from django.conf.urls import url
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
urlpatterns = patterns(
# ...
url(r'^graphql', csrf_exempt(GraphQLView.as_view(graphiql=True))),
# ...
) |
Thanks @syrusakbary |
@syrusakbary I had to do this after deploying my Django app to a live server to get GraphiQL to work on the web. Is that intended or should it find the CSRF token automatically? |
@syrusakbary @nlhkh @Vitiell0 I have been trying to make a solution like this but my JS foo isn't strong enough. |
@syrusakbary is it possible to disable CSRF for a specific resolver/mutation instead of disabling it for everything? I have a resolver that will be used by an external service (not my app), so it's not possible for it to use a CSRF token. But I don't want to disable CSRF entirely just because of that one resolver. |
It would be great if the graphene-django docs could explain how to pass the CSRF token from a javascript client (preferably appollo). If I find out myself I will post it here. My latest attempt looks like this (note: doesn't work):
|
@mnieber bruh
|
Thanks @japrogramer, it looks a bit different from my attempt, but unfortunately it also doesn't work. |
@mnieber maybe your Cookies.get('csrftoken') call isn't working .. |
@mnieber Hmm something like this should work. also try resetting your cache .. just in case. |
The Cookies.get call is working (I checked it in this particular bit of code, and also, I'm using it in my jquery setup) |
@mnieber
|
@dspacejs you could splitting the schema and merging them, one would be csrf exempt and the combined schema wouldnt |
In the end I solved my problem by using the graphql-request package. This also solved another problem where authentication headers were not included in the request. I would suggest to include this (or something similar) in the graphene-django docs, it would be a great help to get started with graphene-django.
|
Strange I don't use that package at all, and my code works for me. |
Many people have encountered the same problem. Usually, the solution for them is to import from 'apollo-client', but that did not work for me. Anyway, I'm happier with a simpler graphql client, so I like this solution. |
It seems Graphiql cannot succesfully set correct CSRF token. Is there a forked version that fixes this? |
@gotexis You can try the advice from syrusakbary, it should work (#61 (comment)) |
@dspacejs You can put the query with that resolver in another scheme and provide another csrf-exempted view with that scheme. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I have the use case of a mobile client app accessing graphql resource with Apollo Client. However, the client cannot access because of CSRF validation. In web I can get the token from cookie, but there is no cookie in mobile app. How can I solve this issue?
The text was updated successfully, but these errors were encountered: