Skip to content

Instantly share code, notes, and snippets.

@nmcspadden
Created October 19, 2016 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmcspadden/2ca26daa288bd510c3d959ba2dc712bb to your computer and use it in GitHub Desktop.
Save nmcspadden/2ca26daa288bd510c3d959ba2dc712bb to your computer and use it in GitHub Desktop.
adobe_tools - Prepare access token
def prepare_access_token(config_data, jwt_token):
"""Generate the access token."""
# Method parameters
url = "https://" + config_data['ims_host'] + config_data['ims_endpoint_jwt']
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control": "no-cache"
}
body_credentials = {
"client_id": config_data['api_key'],
"client_secret": config_data['client_secret'],
"jwt_token": jwt_token
}
body = urlencode(body_credentials)
# send http request
res = requests.post(url, headers=headers, data=body)
# evaluate response
if res.status_code == 200:
# extract token
access_token = json.loads(res.text)["access_token"]
return access_token
else:
# print response
print(res.status_code)
print(res.headers)
print(res.text)
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment