Login using pydgraph

You need to set-up groot

You can use following functions:

def getJWTForGroot():
    url = 'http://localhost:8080/admin'
    q = """mutation {login(userId: "groot", password: "password") {
            response {
                accessJWT
                refreshJWT
            }
        }
    }"""
    headers = {
    'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, json = {'query': q})
    json_data = json.loads(response.text)
    return json_data['data']['login']['response']

def setUpGroot(client):
    client.login("groot", "password")
    accessJWTForGroot = getJWTForGroot()['accessJWT']

After creating users and groups, you can modify the getJWTForGroot to get JWT tokens for other users.

1 Like