-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
34 lines (29 loc) · 959 Bytes
/
auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import urllib.parse
import secrets
import requests
# OAuth setup
CLIENT_ID = os.getenv("CLIENT_ID")
REDIRECT_URI = 'http://localhost:8501/'
ENCODED_REDIRECT_URI = urllib.parse.quote(REDIRECT_URI, safe='')
def get_auth_url():
playerSessionSecret = secrets.token_urlsafe()
AUTH_URL = (
f"https://hydra-public.prod.m3.scopelypv.com/oauth2/auth?"
f"response_type=code&"
f"client_id={CLIENT_ID}&"
f"redirect_uri={ENCODED_REDIRECT_URI}&"
f"state={playerSessionSecret}&"
f"scope=openid+offline+m3p.f.pr.pro+m3p.f.pr.act+m3p.f.pr.ros"
)
return AUTH_URL
def get_access_token(code):
token_url = 'https://hydra-public.prod.m3.scopelypv.com/oauth2/token'
data = {
'grant_type': 'authorization_code',
'client_id': CLIENT_ID,
'code': code,
'redirect_uri': REDIRECT_URI
}
response = requests.post(token_url, data=data)
return response.json()