| import requests, os |
|
|
|
|
| GOOGLE_CLIENT_ID = os.environ.get("GOOGLE_CLIENT_ID", None) |
| GOOGLE_CLIENT_SECRET = os.environ.get("GOOGLE_CLIENT_SECRET", None) |
| OAUTH_REDIRECT = os.environ.get("OAUTH_REDIRECT", None) |
|
|
| def validate_redirect(params): |
| data = { |
| 'code': params["code"], |
| 'redirect_uri': OAUTH_REDIRECT, |
| 'client_id': GOOGLE_CLIENT_ID, |
| 'client_secret': GOOGLE_CLIENT_SECRET, |
| 'scope': params["scope"], |
| 'grant_type': 'authorization_code' |
| } |
|
|
| google_auth_rq = requests.post("https://oauth2.googleapis.com/token", data=data) |
| 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) |
| return google_userinfo_rq.json() |