Spaces:
Runtime error
Runtime error
Download modules/oauth.py from MGLDZM/chgpt: direct link, hf CLI and curl.
- Browser
- Download file 957 Bytes
-
https://huggingface.co/spaces/MGLDZM/chgpt/resolve/main/modules/oauth.py
- Command line
-
hf download hf://spaces/MGLDZM/chgpt/modules/oauth.py
-
curl -L -o oauth.py https://huggingface.co/spaces/MGLDZM/chgpt/resolve/main/modules/oauth.py
957 Bytes
| 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 | |