Skip to content

fix: admin consent screen appears again for user after admin approval#1997

Merged
edwinjosechittilappilly merged 6 commits into
mainfrom
chery-pick-1908
Jul 1, 2026
Merged

fix: admin consent screen appears again for user after admin approval#1997
edwinjosechittilappilly merged 6 commits into
mainfrom
chery-pick-1908

Conversation

@edwinjosechittilappilly

@edwinjosechittilappilly edwinjosechittilappilly commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

chore: Chery pick #1908

Summary by CodeRabbit

  • New Features

    • OAuth sign-in now respects connector-specific prompts, improving how account selection and consent screens are shown during connection.
    • Added clearer handling for Microsoft and cloud storage connections to better support re-authentication and consent flows.
  • Bug Fixes

    • Fixed authentication flows so the correct prompt is used instead of always forcing consent.
    • Improved error handling for SharePoint access, including clearer guidance when admin consent is required.

@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 Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Failed to post review comments.

GitHub was unavailable or timed out while CodeRabbit was posting the review. Please request a new review later if the pull request still needs one. This happened while posting 1 inline comment. Use @coderabbitai full review to retry the review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 408905cd-c7e0-4bdd-881d-ca726629db7a

📥 Commits

Reviewing files that changed from the base of the PR and between 77bd3d6 and e2d7103.

📒 Files selected for processing (6)
  • frontend/app/api/mutations/useConnectConnectorMutation.ts
  • frontend/contexts/auth-context.tsx
  • src/connectors/google_drive/oauth.py
  • src/connectors/onedrive/oauth.py
  • src/connectors/sharepoint/oauth.py
  • src/services/auth_service.py
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: build-images
⚠️ CI failures not shown inline (2)

GitHub Actions: Frontend Lint / React Doctor: fix: admin consent screen appears again for user after admin approval

Conclusion: failure

View job details

##[group]Run SCORE=$(npx -y react-doctor@0.5.8 --score --yes)
 �[36;1mSCORE=$(npx -y react-doctor@0.5.8 --score --yes)�[0m
 �[36;1mecho "React Doctor score: $SCORE"�[0m
 �[36;1mif [ "$SCORE" -lt 40 ]; then�[0m
 �[36;1m  echo "::error::React Doctor score $SCORE is below the minimum threshold of 40"�[0m

GitHub Actions: Frontend Lint / 0_React Doctor.txt: fix: admin consent screen appears again for user after admin approval

Conclusion: failure

View job details

##[group]Run SCORE=$(npx -y react-doctor@0.5.8 --score --yes)
 �[36;1mSCORE=$(npx -y react-doctor@0.5.8 --score --yes)�[0m
 �[36;1mecho "React Doctor score: $SCORE"�[0m
 �[36;1mif [ "$SCORE" -lt 40 ]; then�[0m
 �[36;1m  echo "::error::React Doctor score $SCORE is below the minimum threshold of 40"�[0m
🧰 Additional context used
📓 Path-based instructions (4)
frontend/**

⚙️ CodeRabbit configuration file

Next.js App Router with React 19. Lint and format via Biome — not ESLint. State management via Zustand (stores/) and React Query for server state. UI built on Radix primitives + Tailwind.

Files:

  • frontend/contexts/auth-context.tsx
  • frontend/app/api/mutations/useConnectConnectorMutation.ts
src/**/*.py

⚙️ CodeRabbit configuration file

Use get_logger from utils.logging_config — never import stdlib logging directly. Config values must come from config/settings.py (the only place os.environ is read); never access os.environ elsewhere in the codebase.

Files:

  • src/services/auth_service.py
  • src/connectors/onedrive/oauth.py
  • src/connectors/google_drive/oauth.py
  • src/connectors/sharepoint/oauth.py
src/services/**/*.py

⚙️ CodeRabbit configuration file

Business logic layer. New services must be instantiated in the lifespan block in main.py and injected into routers via src/dependencies.py — never instantiated directly in route handlers.

Files:

  • src/services/auth_service.py
src/connectors/**/*.py

⚙️ CodeRabbit configuration file

External data connectors (Google Drive, OneDrive, S3, IBM COS). New connectors must subclass connectors/base.py and register through connectors/service.py. Verify credentials are never logged, errors surface cleanly, and pagination is handled correctly.

Files:

  • src/connectors/onedrive/oauth.py
  • src/connectors/google_drive/oauth.py
  • src/connectors/sharepoint/oauth.py
🧠 Learnings (1)
📚 Learning: 2026-05-13T20:27:19.613Z
Learnt from: mfortman11
Repo: langflow-ai/openrag PR: 1593
File: frontend/app/chat/page.tsx:51-53
Timestamp: 2026-05-13T20:27:19.613Z
Learning: In the `langflow-ai/openrag` frontend, only use the Zustand store for cross-feature global state. If state is scoped to a specific feature or subtree (e.g., chat-specific state like `loading` held in a chat `ChatContext`), it should be colocated within that feature’s React context (and not moved into a global Zustand store). During reviews, do not flag co-locating feature-scoped state in React Context as a violation of the Zustand convention.

Applied to files:

  • frontend/contexts/auth-context.tsx
  • frontend/app/api/mutations/useConnectConnectorMutation.ts

Walkthrough

This PR replaces the hardcoded OAuth prompt=consent parameter with a connector-configurable value. Google Drive, OneDrive, and SharePoint OAuth classes define an AUTH_PROMPT constant; AuthService.init_oauth surfaces it in oauth_config; frontend code consumes it with a "consent" fallback. SharePoint OAuth also receives broader logging and error-handling refactoring.

Changes

Configurable OAuth Prompt

Layer / File(s) Summary
Backend AUTH_PROMPT constants and propagation
src/connectors/google_drive/oauth.py, src/connectors/onedrive/oauth.py, src/connectors/sharepoint/oauth.py, src/services/auth_service.py
Each connector's OAuth class defines an AUTH_PROMPT constant ("consent" or "select_account"); AuthService.init_oauth reads it (default "consent") and includes prompt in the returned oauth_config.
Frontend dynamic prompt usage
frontend/app/api/mutations/useConnectConnectorMutation.ts, frontend/contexts/auth-context.tsx
ConnectResponse.oauth_config gains an optional prompt field, and both the connect mutation and login flow build the authorization URL using result.oauth_config.prompt ?? "consent" instead of a fixed value.

SharePoint OAuth Logging and Error-Handling Refactor

Layer / File(s) Summary
Typing cleanup
src/connectors/sharepoint/oauth.py
Imports simplified to Any only, _current_account typed as `dict[str, Any]
Credential loading and refresh migration
src/connectors/sharepoint/oauth.py
load_credentials() saves cache on upgrade and uses RESOURCE_SCOPES for silent acquisition; _refresh_from_json_token() builds consolidated error strings, detects specific auth failures, and simplifies exception handling.
Authorization URL and callback handling
src/connectors/sharepoint/oauth.py
create_authorization_url() updates typing and kwargs construction; handle_authorization_callback() refactors error_msg derivation.
Authentication and token acquisition
src/connectors/sharepoint/oauth.py
is_authenticated(), get_access_token(), and get_access_token_for_resource() gain expanded logging, fallback acquisition logic, and dedicated ValueErrors for admin-consent failures.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Frontend
  participant AuthService
  participant ConnectorOAuthClass

  Frontend->>AuthService: init_oauth(connector)
  AuthService->>ConnectorOAuthClass: read AUTH_PROMPT
  ConnectorOAuthClass-->>AuthService: AUTH_PROMPT value
  AuthService-->>Frontend: oauth_config with prompt
  Frontend->>Frontend: build authorization URL using prompt ?? "consent"
Loading
sequenceDiagram
  participant Caller
  participant SharePointOAuth
  participant MSAL

  Caller->>SharePointOAuth: get_access_token_for_resource()
  SharePointOAuth->>MSAL: acquire_token_silent(account)
  MSAL-->>SharePointOAuth: result or error
  alt error contains AADSTS65001 or "consent"
    SharePointOAuth-->>Caller: raise ValueError (admin consent required)
  else other failure
    SharePointOAuth-->>Caller: raise ValueError (chained)
  end
Loading

Possibly related PRs

  • langflow-ai/openrag#1657: Introduced the original hardcoded prompt=consent logic in useConnectConnectorMutation.ts and auth-context.tsx that this PR generalizes.
  • langflow-ai/openrag#1908: Overlaps with the same frontend/backend files and SharePoint OAuth adjustments for connector-specific prompt propagation.

Suggested labels: refactor

Suggested reviewers: mfortman11

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: fixing the OAuth flow so users are not re-prompted for admin consent after approval.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chery-pick-1908

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit e2d7103.

@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Jul 1, 2026
@github-actions github-actions Bot added the lgtm label Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/connectors/sharepoint/oauth.py (1)

348-467: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Hydrate the token cache before these silent-acquisition paths.

load_credentials() is the only visible path here that deserializes self.token_file into self.token_cache and restores _current_account. Both get_access_token() and get_access_token_for_resource() now call acquire_token_silent(...) directly, so a freshly instantiated connector after process restart will fall into the failure path until some other caller has already run is_authenticated(). Please restore cache loading before these sync token getters, or move the hydration into connector initialization.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/connectors/sharepoint/oauth.py` around lines 348 - 467, Both SharePoint
silent token paths are using acquire_token_silent without ensuring the MSAL
cache has been restored first. Update get_access_token() and
get_access_token_for_resource() in SharePointOauth to hydrate state by calling
the same cache-loading logic used by load_credentials() before any silent
acquisition, or move that hydration into the connector’s initialization so
_current_account and token_cache are always ready after restart.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/connectors/sharepoint/oauth.py`:
- Around line 3-4: The SharePoint OAuth module is still using stdlib logging
instead of the required project logger; update the imports and logger
initialization in oauth.py so it uses get_logger from utils.logging_config
rather than logging.getLogger. Remove the direct logging dependency, keep the
existing logger symbol in place for the rest of the module, and ensure any
logging calls in this file continue to use that get_logger-based logger.

---

Outside diff comments:
In `@src/connectors/sharepoint/oauth.py`:
- Around line 348-467: Both SharePoint silent token paths are using
acquire_token_silent without ensuring the MSAL cache has been restored first.
Update get_access_token() and get_access_token_for_resource() in SharePointOauth
to hydrate state by calling the same cache-loading logic used by
load_credentials() before any silent acquisition, or move that hydration into
the connector’s initialization so _current_account and token_cache are always
ready after restart.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 408905cd-c7e0-4bdd-881d-ca726629db7a

📥 Commits

Reviewing files that changed from the base of the PR and between 77bd3d6 and e2d7103.

📒 Files selected for processing (6)
  • frontend/app/api/mutations/useConnectConnectorMutation.ts
  • frontend/contexts/auth-context.tsx
  • src/connectors/google_drive/oauth.py
  • src/connectors/onedrive/oauth.py
  • src/connectors/sharepoint/oauth.py
  • src/services/auth_service.py

Comment on lines +3 to +4
import os
from typing import Any

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use get_logger here instead of stdlib logging.

This module still initializes logger via logging.getLogger(...) on Line 8, so the header cleanup leaves the file out of compliance with the src/**/*.py logging rule. Please switch this file to get_logger while you're already touching the imports. As per path instructions, src/**/*.py: Use get_logger from utils.logging_config — never import stdlib logging directly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/connectors/sharepoint/oauth.py` around lines 3 - 4, The SharePoint OAuth
module is still using stdlib logging instead of the required project logger;
update the imports and logger initialization in oauth.py so it uses get_logger
from utils.logging_config rather than logging.getLogger. Remove the direct
logging dependency, keep the existing logger symbol in place for the rest of the
module, and ensure any logging calls in this file continue to use that
get_logger-based logger.

Source: Path instructions

@edwinjosechittilappilly
edwinjosechittilappilly merged commit 08b68ed into main Jul 1, 2026
30 checks passed
@github-actions
github-actions Bot deleted the chery-pick-1908 branch July 1, 2026 20:12
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 lgtm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants