-
-
Save nmcspadden/2ca26daa288bd510c3d959ba2dc712bb to your computer and use it in GitHub Desktop.
adobe_tools - Prepare access token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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