[PR #18415] [MERGED] enh: More detailed OAuth2.1 tool callback error handling + fix for editing existing tools #24784

Closed
opened 2026-04-20 05:35:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/18415
Author: @taylorwilsdon
Created: 10/18/2025
Status: Merged
Merged: 10/27/2025
Merged by: @tjbck

Base: devHead: oauth_error_handling_enh


📝 Commits (5)

  • 40c450e Add more granular information to oauth failure messages
  • c107a37 Added a targeted utility to wipe all OAuth sessions for a provider so the cleanup can remove stale access tokens across every user when a connection is updated
  • d49fb9c complete cleanup of oauth clients
  • ecbf74d Added a preflight authorize check that automatically re-registers MCP OAuth clients when the stored client ID no longer exists on the server, so the browser flow never hits the stale-ID failure
  • 4b74034 black fmt

📊 Changes

3 files changed (+327 additions, -7 deletions)

View changed files

📝 backend/open_webui/models/oauth_sessions.py (+11 -0)
📝 backend/open_webui/routers/configs.py (+50 -1)
📝 backend/open_webui/utils/oauth.py (+266 -6)

📄 Description

Pull Request Checklist

Closes https://github.com/open-webui/open-webui/discussions/18309

@tjbck I have tested this one extensively and it solves several of my real world issues. Will continue to build on the degree of specificity in the error messages but I'd call this safe to merge as-is.

Before submitting, make sure you've checked the following:

  • Target branch: Verify that the pull request targets the dev branch. Not targeting the dev branch may lead to immediate closure of the PR.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: If necessary, update relevant documentation Open WebUI Docs like environment variables, the tutorials, or other documentation sources.
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Perform manual tests to verify the implemented fix/feature works as intended AND does not break any other functionality. Take this as an opportunity to make screenshots of the feature/fix and include it in the PR description.
  • Agentic AI Code:: Confirm this Pull Request is not written by any AI Agent or has at least gone through additional human review and manual testing. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR.
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Title Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

  • Sharpen OAuth callback error messaging and ensure edited OAuth 2.1 MCP connections refresh their client registrations so traffic routes to the updated endpoint without unauthorized_client failures.
  • Added a preflight authorize check that automatically re-registers MCP OAuth clients when the stored client ID no longer exists on the server, so the browser flow never hits the stale-ID failure

Added

  • Helper _build_oauth_callback_error_message to translate backend exceptions into actionable callback detail strings.
  • Provider-wide OAuth session purge utility to support MCP connection resets.
  • Preflight auth check that automatically re-registers MCP OAuth clients when the stored client ID no longer exists on the server, so the browser flow never hits the stale-ID failure

Changed

  • MCP connection save flow now drops and re-registers OAuth 2.1 clients when identifiers, auth modes, or endpoints change.
  • Authlib client removal clears internal caches to prevent stale dynamic-registration metadata from persisting across edits.
  • Redirect error payloads are URL-encoded with the detailed message.

Deprecated

  • None.

Removed

  • None.

Fixed

  • Resolved stale OAuth client registrations that caused unauthorized_client errors after editing streamable-http MCP endpoints.
  • Replaced the generic “OAuth callback error” UI message with contextual feedback sourced from the upstream provider responses.

Security

  • No change

Breaking Changes

  • No change

Additional Information

Screenshots or Videos

Screenshot 2025-10-18 at 2 07 15 PM

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/18415 **Author:** [@taylorwilsdon](https://github.com/taylorwilsdon) **Created:** 10/18/2025 **Status:** ✅ Merged **Merged:** 10/27/2025 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `oauth_error_handling_enh` --- ### 📝 Commits (5) - [`40c450e`](https://github.com/open-webui/open-webui/commit/40c450e6e54303ead5473476f0c2519cd928ae9e) Add more granular information to oauth failure messages - [`c107a37`](https://github.com/open-webui/open-webui/commit/c107a3799f3695e57c303544dc93cadbdeb91c0a) Added a targeted utility to wipe all OAuth sessions for a provider so the cleanup can remove stale access tokens across every user when a connection is updated - [`d49fb9c`](https://github.com/open-webui/open-webui/commit/d49fb9c01038dc580b2229ac2554727506357372) complete cleanup of oauth clients - [`ecbf74d`](https://github.com/open-webui/open-webui/commit/ecbf74dbea59534cebdd3ce1a40749fcfd68133e) Added a preflight authorize check that automatically re-registers MCP OAuth clients when the stored client ID no longer exists on the server, so the browser flow never hits the stale-ID failure - [`4b74034`](https://github.com/open-webui/open-webui/commit/4b7403496795fd7476243e7b6a48292c0cfe1b4b) black fmt ### 📊 Changes **3 files changed** (+327 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/models/oauth_sessions.py` (+11 -0) 📝 `backend/open_webui/routers/configs.py` (+50 -1) 📝 `backend/open_webui/utils/oauth.py` (+266 -6) </details> ### 📄 Description # Pull Request Checklist Closes https://github.com/open-webui/open-webui/discussions/18309 @tjbck I have tested this one extensively and it solves several of my real world issues. Will continue to build on the degree of specificity in the error messages but I'd call this safe to merge as-is. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Verify that the pull request targets the `dev` branch. Not targeting the `dev` branch may lead to immediate closure of the PR. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [x] **Documentation:** If necessary, update relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs) like environment variables, the tutorials, or other documentation sources. - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Perform manual tests to verify the implemented fix/feature works as intended AND does not break any other functionality. Take this as an opportunity to make screenshots of the feature/fix and include it in the PR description. - [x] **Agentic AI Code:**: Confirm this Pull Request is **not written by any AI Agent** or has at least gone through additional human review **and** manual testing. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR. - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Title Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description - Sharpen OAuth callback error messaging and ensure edited OAuth 2.1 MCP connections refresh their client registrations so traffic routes to the updated endpoint without `unauthorized_client` failures. - Added a preflight authorize check that automatically re-registers MCP OAuth clients when the stored client ID no longer exists on the server, so the browser flow never hits the stale-ID failure ### Added - Helper `_build_oauth_callback_error_message` to translate backend exceptions into actionable callback detail strings. - Provider-wide OAuth session purge utility to support MCP connection resets. - Preflight auth check that automatically re-registers MCP OAuth clients when the stored client ID no longer exists on the server, so the browser flow never hits the stale-ID failure ### Changed - MCP connection save flow now drops and re-registers OAuth 2.1 clients when identifiers, auth modes, or endpoints change. - Authlib client removal clears internal caches to prevent stale dynamic-registration metadata from persisting across edits. - Redirect error payloads are URL-encoded with the detailed message. ### Deprecated - None. ### Removed - None. ### Fixed - Resolved stale OAuth client registrations that caused `unauthorized_client` errors after editing streamable-http MCP endpoints. - Replaced the generic “OAuth callback error” UI message with contextual feedback sourced from the upstream provider responses. ### Security - No change ### Breaking Changes - No change --- ### Additional Information ### Screenshots or Videos <img width="437" height="140" alt="Screenshot 2025-10-18 at 2 07 15 PM" src="https://github.com/user-attachments/assets/be598036-877e-4879-9bcf-cbc352714a6b" /> ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 05:35:26 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#24784