Skip to content

Instantly share code, notes, and snippets.

@ctian1
Forked from Luc1412/auth_flow.py
Created January 5, 2021 02:16
Show Gist options
  • Save ctian1/a249604f9143741bd76e45133b5e1de8 to your computer and use it in GitHub Desktop.
Save ctian1/a249604f9143741bd76e45133b5e1de8 to your computer and use it in GitHub Desktop.
This is the auth flow for valorant (async)
import re
import aiohttp
async def run(username, password):
session = aiohttp.ClientSession()
data = {
'client_id': 'play-valorant-web-prod',
'nonce': '1',
'redirect_uri': 'https://beta.playvalorant.com/opt_in',
'response_type': 'token id_token',
}
await session.post('https://auth.riotgames.com/api/v1/authorization', json=data)
data = {
'type': 'auth',
'username': username,
'password': password
}
async with session.put('https://auth.riotgames.com/api/v1/authorization', json=data) as r:
data = await r.json()
pattern = re.compile('access_token=((?:[a-zA-Z]|\d|\.|-|_)*).*id_token=((?:[a-zA-Z]|\d|\.|-|_)*).*expires_in=(\d*)')
data = pattern.findall(data['response']['parameters']['uri'])[0]
access_token = data[0]
print('Access Token: ' + access_token)
id_token = data[1]
expires_in = data[2]
headers = {
'Authorization': f'Bearer {access_token}',
}
async with session.post('https://entitlements.auth.riotgames.com/api/token/v1', headers=headers, json={}) as r:
data = await r.json()
entitlements_token = data['entitlements_token']
print('Entitlements Token: ' + entitlements_token)
async with session.post('https://auth.riotgames.com/userinfo', headers=headers, json={}) as r:
data = await r.json()
user_id = data['sub']
print('User ID: ' + user_id)
headers['X-Riot-Entitlements-JWT'] = entitlements_token
# Example Request. (Access Token and Entitlements Token needs to be included!)
async with session.get(f'https://pd.eu.a.pvp.net/match-history/v1/history/{user_id}?startIndex=0&endIndex=10', headers=headers) as r:
data = json.loads(await r.text())
print(data)
await session.close()
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(run('exmaple user name', 'my_secret_password'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment