make better

This commit is contained in:
Taylor Wilsdon
2026-03-01 17:34:02 -05:00
parent 3361ed29e6
commit ef9c6a9c69

View File

@@ -295,6 +295,7 @@ def create_oauth_flow(
redirect_uri: str, redirect_uri: str,
state: Optional[str] = None, state: Optional[str] = None,
code_verifier: Optional[str] = None, code_verifier: Optional[str] = None,
autogenerate_code_verifier: bool = True,
) -> Flow: ) -> Flow:
"""Creates an OAuth flow using environment variables or client secrets file.""" """Creates an OAuth flow using environment variables or client secrets file."""
flow_kwargs = { flow_kwargs = {
@@ -308,10 +309,10 @@ def create_oauth_flow(
flow_kwargs["autogenerate_code_verifier"] = False flow_kwargs["autogenerate_code_verifier"] = False
else: else:
# Generate PKCE code verifier for the initial auth flow. # Generate PKCE code verifier for the initial auth flow.
# Without this, oauthlib 3.2+ adds code_challenge to the auth URL # google-auth-oauthlib's from_client_* helpers pass
# at the session level, but Flow.code_verifier stays None. # autogenerate_code_verifier=None unless explicitly provided, which
# Google then rejects the token exchange with "Missing code verifier". # prevents Flow from generating and storing a code_verifier.
flow_kwargs["autogenerate_code_verifier"] = True flow_kwargs["autogenerate_code_verifier"] = autogenerate_code_verifier
# Try environment variables first # Try environment variables first
env_config = load_client_secrets_from_env() env_config = load_client_secrets_from_env()
@@ -526,6 +527,7 @@ def handle_auth_callback(
redirect_uri=redirect_uri, redirect_uri=redirect_uri,
state=state, state=state,
code_verifier=state_info.get("code_verifier"), code_verifier=state_info.get("code_verifier"),
autogenerate_code_verifier=False,
) )
# Exchange the authorization code for credentials # Exchange the authorization code for credentials