Skip to content

Instantly share code, notes, and snippets.

@ShayMe21
Created November 21, 2018 22:17
Show Gist options
  • Save ShayMe21/e25f0c90fa219971fde0cc11d7a93e7b to your computer and use it in GitHub Desktop.
Save ShayMe21/e25f0c90fa219971fde0cc11d7a93e7b to your computer and use it in GitHub Desktop.
###--------Modules-------------------------------------------------------------#
import requests
import json
###--------Functions-----------------------------------------------------------#
clientId="nNVpnD0SxI1GI87ZvNiMOn1MOaWXw3gp"
clientSecret="--"
url="shayanmemari.au.auth0.com"
customer="testing-BFP1"
def getAccessToken(clientId, clientSecret, url):
payload = "{\"grant_type\":\"client_credentials\",\"client_id\": \"" + clientId + \
"\",\"client_secret\": \"" + clientSecret + \
"\",\"audience\": \"https://" + url + "/api/v2/\"}"
headers = {'content-type': "application/json"}
r = requests.post("https://" + url + "/oauth/token",
headers=headers, data=payload)
access_token = r.json()['access_token']
headers = {
'authorization': "Bearer " + access_token,
'content-type': "application/json"
}
return headers
def getRequest(url, tail, h):
headers = json.loads(h)
r = requests.get("https://" + url + "/api/v2/" + tail, headers=headers)
j = r.json()
return j
def postRequest(url, tail, h, d):
headers = json.loads(h)
headers['content-type'] = 'application/json'
r = requests.post("https://" + url + "/api/v2/" +
tail, headers=headers, json=d)
return r.text
def patchRequest(url, tail, h, d):
headers = json.loads(h)
headers['content-type'] = 'application/json'
r = requests.patch("https://" + url + "/api/v2/" +
tail, headers=headers, json=d)
return r.text
###--------Main----------------------------------------------------------------#
h = json.dumps(getAccessToken(clientId, clientSecret, url)) # Auth Bearer Token
#print(h)
tail = "connections?name=" + customer
j = getRequest(url, tail, h)
id = j[0]['id']
print(id)
j[0]['options']["entityId2"] = "https://" + \
url + "/login/callback?connection=" + customer
d = {'options': j[0]['options']}
#d = json.dumps(d)
#print (d)
tail = "connections/" + j[0]['id']
j = patchRequest(url, tail, h, d)
print(j) # Prints updated connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment