quantvat / src /services /google_oauth.py
heisbuba's picture
Upload 3 files
ba306fd verified
Raw History Blame
929 Bytes
import os
from google_auth_oauthlib.flow import Flow
FOLDER_MIME = 'application/vnd.google-apps.folder'
def build_flow(scopes):
"""Create a Google OAuth flow for the given scopes."""
redirect_uri = os.environ.get("GOOGLE_REDIRECT_URI", "")
if redirect_uri.startswith("http://"):
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
else:
os.environ.pop('OAUTHLIB_INSECURE_TRANSPORT', None)
os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'
return Flow.from_client_config(
client_config={
"web": {
"client_id": os.environ.get("GOOGLE_CLIENT_ID"),
"client_secret": os.environ.get("GOOGLE_CLIENT_SECRET"),
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
}
},
scopes=scopes,
redirect_uri=redirect_uri or None,
)