Skip to content

fix: update OAuth parameters for improved consent handling and token …#1149

Open
ricofurtado wants to merge 2 commits intomainfrom
google-drive-issues-backup
Open

fix: update OAuth parameters for improved consent handling and token …#1149
ricofurtado wants to merge 2 commits intomainfrom
google-drive-issues-backup

Conversation

@ricofurtado
Copy link
Collaborator

@ricofurtado ricofurtado commented Mar 13, 2026

Root cause was in auth state, not the upload page UI.

Google connection was being marked unauthenticated because token expiry was interpreted incorrectly (timezone-naive handling), so authenticate() returned False.

The current Google token file also has no refresh_token, so once access token expires it cannot auto-refresh.
I patched this end-to-end:

-Normalized stored OAuth expiry to naive UTC at load time (compatible with google-auth): oauth.py

-Saved callback expiry in UTC and preserve existing refresh_token when provider omits it on re-consent.

-Added Google OAuth params to request offline refresh token consistently (include_granted_scopes=true, prompt=consent) in both login and connector connect flows)

-Made some changes in UI, so Mike needs to validate.

@github-actions github-actions bot added frontend 🟨 Issues related to the UI/UX backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. labels Mar 13, 2026
@github-actions github-actions bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Mar 13, 2026
@ricofurtado ricofurtado requested a review from Copilot March 13, 2026 16:47
@ricofurtado ricofurtado requested a review from mpawlow March 13, 2026 16:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates OAuth token persistence and authorization parameters to improve Google consent handling, ensure refresh token availability, and fix token expiry interpretation.

Changes:

  • Preserve an existing refresh_token when the token callback omits it; store id_token when returned.
  • Save callback expiry in UTC and normalize Google token expiry parsing to naive UTC for google-auth compatibility.
  • Update frontend OAuth authorization URL parameters to request offline access more consistently.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/services/auth_service.py Preserves refresh tokens across re-consent, stores id_token, and writes expiry as UTC.
src/connectors/google_drive/oauth.py Normalizes stored expiry to naive UTC when loading Google credentials.
frontend/contexts/auth-context.tsx Adjusts Google login authorization URL parameters (include_granted_scopes, prompt).
frontend/app/api/mutations/useConnectConnectorMutation.ts Adjusts connector connect authorization URL parameters (currently applied to all connectors).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 56 to +65
if token_data.get("expiry"):
from datetime import datetime

expiry_dt = datetime.fromisoformat(token_data["expiry"])
# Remove timezone info to make it naive (Google auth expects naive datetimes)
self.creds.expiry = expiry_dt.replace(tzinfo=None)
if expiry_dt.tzinfo is None:
local_tz = datetime.now().astimezone().tzinfo
expiry_dt = expiry_dt.replace(tzinfo=local_tz)

# google-auth compares against a naive UTC timestamp internally.
self.creds.expiry = (
expiry_dt.astimezone(timezone.utc).replace(tzinfo=None)
)
Comment on lines 79 to 82
`access_type=offline&` +
`prompt=select_account&` +
`include_granted_scopes=true&` +
`prompt=consent&` +
`state=${result.connection_id}`;
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Mar 13, 2026
Copy link
Collaborator

@edwinjosechittilappilly edwinjosechittilappilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rico lets test this once you are free after reverting the changes in a headers changes in auth context and useConnect...

@mpawlow mpawlow removed their request for review March 14, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. frontend 🟨 Issues related to the UI/UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants