3

I downloaded django app which has regular django api. App is really big and I decided to implement django graphene module and to make more flexible api. I have a graphene view which allow sending requests and receiving responses. My problem is that I want to add authentication on graphene view, so every user needs to provide token or username and password to be able to fetch the records.

I found some solution here: Adding LoginRequiredMixin in new view

My problem is I can't login into django app using curl to execute some grapql query.

What I tried so far:

curl -u admin:password123 -X GET http://localhost:8003/graphql?query=query%7B%20types%20%7B%20edges%20%7B%20node%20%7B%20name%20%7D%20%7D%20%7D%20%7D

using jwt_auth

curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwidXNlcl9pZCI6MSwiZW1haWwiOiIiLCJleHAiOjE0OTg3NDA4OTR9.FvofAxyhvjTGNZBUUSRF1kmXfgTNja6U52NynLhBGeo" http://localhost:8003/graphql?query=query%7B%20types%20%7B%20edges%20%7B%20node%20%7B%20name%20%7D%20%7D%20%7D%20%7

default app way to login on existing api to my graphene view

curl -H "Authorization: Token 2867936fff9d738ee5fc8a807c86a96e59ab648d" http://localhost:8003/graphql?query=query%7B%20types%20%7B%20edges%20%7B%20node%20%7B%20name%20%7D%20%7D%20%7D%20%7D
Misa
  • 51
  • 1
  • 6
  • The way you're trying to login works for Basic HTTP Auth. Django uses cookies, so it won't work this way. See this: https://stackoverflow.com/questions/12399087/curl-to-access-a-page-that-requires-a-login-from-a-different-page – xyres Jun 29 '17 at 15:22

1 Answers1

0

You can use insomnia as an alternative to curl to send graphql queries to your api. It is easy to setup the headers and authenticate.

django-graphql-auth have a demo video with insomnia, showing how to register and authenticate an user with it.

pedrobern
  • 1,134
  • 9
  • 24