Spaces:
Running
Running
import requests | |
from . import settings | |
def validate_redirect(params): | |
data = { | |
'code': params["code"], | |
'redirect_uri': settings.OAUTH_REDIRECT, | |
'client_id': settings.GOOGLE_CLIENT_ID, | |
'client_secret': settings.GOOGLE_CLIENT_SECRET, | |
'scope': params["scope"], | |
'grant_type': 'authorization_code' | |
} | |
google_auth_rq = requests.post("https://oauth2.googleapis.com/token", data=data, timeout=30) | |
google_auth = google_auth_rq.json() | |
try: | |
headers = { | |
'Authorization': google_auth["token_type"]+" "+google_auth["access_token"] | |
} | |
except Exception as e: | |
print(e) | |
print(google_auth_rq.content) | |
return str(e)+" "+google_auth_rq.content | |
google_userinfo_rq = requests.get("https://www.googleapis.com/oauth2/v2/userinfo", headers=headers, timeout=30) | |
ret = google_userinfo_rq.json() | |
ret["gid"] = ret.get("id","") | |
return ret | |