Skip to content

Instantly share code, notes, and snippets.

@rmondragon
Created August 22, 2018 17:21
Show Gist options
  • Save rmondragon/198fa3e47186f09dd86f114d128eee64 to your computer and use it in GitHub Desktop.
Save rmondragon/198fa3e47186f09dd86f114d128eee64 to your computer and use it in GitHub Desktop.
ONE by AOL Get Token
import json
import uuid
import requests
import jwt
import datetime
def get_jwt_token(client_id, secret):
millis = datetime.datetime.utcnow()
plus10min = millis + datetime.timedelta(minutes=10)
payload = {
'aud': "https://id.corp.aol.com/identity/oauth2/access_token?realm=aolcorporate/aolexternals",
'iss': client_id,
'sub': client_id,
'iat': millis,
'exp': plus10min,
'jti': str(uuid.uuid4())
}
encoded = jwt.encode(payload, secret, algorithm='HS256')
return encoded.decode('utf-8')
def get_oauth_token(token):
url = "https://id.corp.aol.com/identity/oauth2/access_token"
payload = "grant_type=client_credentials" \
"&scope=one" \
"&realm=aolcorporate/aolexternals" \
"&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer" \
"&client_assertion=" + token
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'Accept': "application/json",
'Cache-Control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers)
return response.text
def get_reports_list(org_id, token_type, access_token):
url = "https://onevideo.aol.com/reporting/list_reports"
querystring = {"org_id": org_id, "_ps": "0", "_pc": "10", "_o": "ASC", "list_type": "ALL"}
headers = {
'Authorization': "%s %s" % (token_type, access_token),
'Cache-Control': "no-cache"
}
response = requests.request("GET", url, headers=headers, params=querystring)
return response.text
if __name__ == '__main__':
client_id = "YOUR CLIENT ID HERE"
secret = "YOUR SECRET HERE"
org_id = "YOUR ORG ID"
jwt_token = get_jwt_token(client_id, secret)
json_obj = json.loads(get_oauth_token(jwt_token))
report_list = get_reports_list(org_id=org_id,
token_type=json_obj['token_type'],
access_token=json_obj['access_token'])
print(report_list)
@afilgueira
Copy link

Rolando, tu ejemplo me ha salvado. Muchas gracias por compartirlo.

@andremacola
Copy link

I created another solution working with python 3.8+ and javascript
for whoever is interested : https://github.com/andremacola/verizon-oauth-token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment