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

CSRF Exemption? #84

Open
KrishyV opened this issue Sep 18, 2020 · 1 comment
Open

CSRF Exemption? #84

KrishyV opened this issue Sep 18, 2020 · 1 comment

Comments

@KrishyV
Copy link

KrishyV commented Sep 18, 2020

With Django and Graphene users can do the following to exempt the graphql endpoint from CSRF authentication.

urlpatterns = [
    path("admin/", admin.site.urls),
    path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True, schema=schema))),
]

How can one do this with Flask-GraphQL?

app.add_url_rule(
    '/graphql',
    view_func=GraphQLView.as_view(
        'graphql',
        schema=schema,
        graphiql=True

    )
)```
@KrishyV
Copy link
Author

KrishyV commented Sep 24, 2020

Not quite a solution as elegant as what Django has but here is what I did.

I created a Blueprint just for my GraphQL API and exempted the whole blueprint from CSRF.

api.add_url_rule(
    '/graphql',
    view_func=GraphQLView.as_view(
        'graphql',
        schema=schema,
        graphiql=True
    )
)

csrf.exempt(api)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant