Spaces:
Sleeping
Sleeping
Update app/google_oauth.py
Browse files- app/google_oauth.py +15 -3
app/google_oauth.py
CHANGED
|
@@ -15,7 +15,7 @@ SCOPES = [
|
|
| 15 |
TOKEN_FILENAME = "google_token.json"
|
| 16 |
DATA_DIR = Path("/data")
|
| 17 |
FALLBACK_DATA_DIR = Path(tempfile.gettempdir()) / "tcc2_agent"
|
| 18 |
-
|
| 19 |
|
| 20 |
class GoogleOAuthError(RuntimeError):
|
| 21 |
pass
|
|
@@ -76,20 +76,32 @@ def _client_config():
|
|
| 76 |
}
|
| 77 |
|
| 78 |
|
| 79 |
-
def build_flow(state=None):
|
| 80 |
redirect_uri = os.environ.get("GOOGLE_REDIRECT_URI", "").strip()
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
flow.redirect_uri = redirect_uri
|
| 83 |
return flow
|
| 84 |
|
| 85 |
|
| 86 |
def get_authorization_url():
|
| 87 |
flow = build_flow()
|
|
|
|
| 88 |
authorization_url, state = flow.authorization_url(
|
| 89 |
access_type="offline",
|
| 90 |
prompt="consent",
|
| 91 |
include_granted_scopes="true",
|
| 92 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
return authorization_url, state
|
| 94 |
|
| 95 |
|
|
|
|
| 15 |
TOKEN_FILENAME = "google_token.json"
|
| 16 |
DATA_DIR = Path("/data")
|
| 17 |
FALLBACK_DATA_DIR = Path(tempfile.gettempdir()) / "tcc2_agent"
|
| 18 |
+
OAUTH_TEMP = {}
|
| 19 |
|
| 20 |
class GoogleOAuthError(RuntimeError):
|
| 21 |
pass
|
|
|
|
| 76 |
}
|
| 77 |
|
| 78 |
|
| 79 |
+
def build_flow(state=None, code_verifier=None):
|
| 80 |
redirect_uri = os.environ.get("GOOGLE_REDIRECT_URI", "").strip()
|
| 81 |
+
|
| 82 |
+
flow = Flow.from_client_config(
|
| 83 |
+
_client_config(),
|
| 84 |
+
scopes=SCOPES,
|
| 85 |
+
state=state,
|
| 86 |
+
code_verifier=code_verifier,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
flow.redirect_uri = redirect_uri
|
| 90 |
return flow
|
| 91 |
|
| 92 |
|
| 93 |
def get_authorization_url():
|
| 94 |
flow = build_flow()
|
| 95 |
+
|
| 96 |
authorization_url, state = flow.authorization_url(
|
| 97 |
access_type="offline",
|
| 98 |
prompt="consent",
|
| 99 |
include_granted_scopes="true",
|
| 100 |
)
|
| 101 |
+
|
| 102 |
+
OAUTH_TEMP["state"] = state
|
| 103 |
+
OAUTH_TEMP["code_verifier"] = flow.code_verifier
|
| 104 |
+
|
| 105 |
return authorization_url, state
|
| 106 |
|
| 107 |
|