File size: 929 Bytes
ba306fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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,
    )