Mike Party Posted December 16, 2020 Share Posted December 16, 2020 I am trying to connect to a GraphQL endpoint using JWT authtentication. To connect to this particular endpoint, I need to pass a login mutation (see below) as a POST request. Anyone have experience with this or guidance I've been trying to do this with a WebRequest, but I can't figure out how to pass the mutation for the login credentials.... mutation { logIn( email:"you@youremail.com", password:"yourpassword") { jwt { token exp } } } Link to comment Share on other sites More sharing options...
Mike Party Posted December 21, 2020 Author Share Posted December 21, 2020 In Python, the code looks like below. Unfortunately, IronPython 2.7.7 does not have the requests module, trying to find a work around. import requests import json address = "http://www.website.com" logIn = """ mutation { logIn( email:"you@email.com", password:"password") { jwt { token exp } } } """ request = requests.post(address, json={'query': logIn}) Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted December 21, 2020 Share Posted December 21, 2020 Below is a sample script I used to make a webrequest using httplib and urllib modules in Python. can you pass the mutation for login as a parameter in the below script and see if it helps import httplib,urllib conn = httplib.HTTPConnection("IPaddress",port) params = urllib.urlencode({'grant_type':'client_credentials', 'scope': 'someScope'}) headers={"Content-type": "application/x-www-form-urlencoded", "Authorization":"Basic YTIwNWNmYWVmN2YxNTExOWMyZmQwM"} conn.request("POST", "URLendpoint",params,headers) response = conn.getresponse() print response.status, response.reason data = response.read() print data Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now