issue: OAuth scopes are still missing within authorize_url when using MCP with OAuth2.1 (Static)

用户在 Open WebUI v0.9.6(Docker 安装方式)中配置 MCP 工具并使用 OAuth 2.1 (Static) 授权模式连接需要通过 scope 参数验证的身份提供者(如 Azure Entra ID、Google Gmail/Calendar 等)时,在浏览器中触发 OAut

issue: OAuth scopes are still missing within authorize_url when using MCP with OAuth2.1 (Static)

issue: OAuth scopes are still missing within authorize_url when using MCP with OAuth2.1 (Static)

快速结论:在 Open WebUI v0.9.6 中配置 MCP 使用 OAuth 2.1 (Static) 且接入需要 scope 的参数的身份提供者(如 Azure Entra ID)时,authorize_url 中缺少 scope 参数,导致身份提供者拒绝授权请求(例如 Entra 报错 AADSTS900144)。这个 bug 在 PR #24690 中声称修复,但实际上 scope 在持久化/加载链条中丢失了。

问题场景

用户在 Open WebUI v0.9.6(Docker 安装方式)中配置 MCP 工具并使用 OAuth 2.1 (Static) 授权模式连接需要通过 scope 参数验证的身份提供者(如 Azure Entra ID、Google Gmail/Calendar 等)时,在浏览器中触发 OAuth 授权流程,但身份提供者因为授权 URL 中缺少 scope 而拒绝请求。

报错原文

Debug logging shows:
client_info.scope=None
client_kwargs={'follow_redirects': True, 'token_endpoint_auth_method': 'client_secret_post'}
kwargs={}

IdP rejects with (Azure Entra ID):
AADSTS900144: The request body must contain the following parameter: 'scope'.

原因分析

scope 在以下链条中丢失了:

  • Build 阶段(正确):get_oauth_client_info_with_static_credentials(约第 529 行)从 /.well-known/oauth-protected-resource 发现 scope,并正确构建了一个包含 scope 的 OAuthClientInformationFull 对象。
  • Persist 阶段(正确):该对象被加密并作为 blob 存储在连接配置的 info.oauth_client_info 中。
  • Load 阶段(错误):ensure_client_from_config(约第 691 行)调用 resolve_oauth_client_info 解密 blob 为 dict,然后通过 OAuthClientInformationFull(**dict) 重构对象。如果 blob 是在 PR #24690 之前创建的,则 dict 中缺少 scope 字段,导致重构后的对象 scope=None

此外,_preflight_authorization_url 在调用 create_authorization_url(redirect_uri=redirect_uri) 时也未传递 scope,因此在 handle_authorize 执行之前,预检检查就已经失败了。

环境排查

  • Open WebUI 版本:v0.9.6(已知有该问题的版本)
  • 安装方式:Docker
  • 操作系统:Windows 11 搭配 WSL 2(Ubuntu 26.04 LTS)
  • 浏览器:Edge 149.0.4022.52
  • 身份提供者:Azure Entra ID、Google Gmail/Calendar 等
  • 相关文件:open_webui/utils/oauth.py

解决步骤

  1. 确认问题是否因旧的连接配置引起:如果配置 blob 是在 PR #24690 之前创建的,scope 字段会丢失。可以尝试删除现有的 MCP OAuth 2.1 (Static) 连接配置,然后重新创建。

  2. 检查 scope 是否丢失:handle_authorize 中加入调试日志,确认 client_info.scope 是否为 None

  3. 可能的代码修复(可优先尝试):handle_authorize 中,在调用 authorize_redirect 之前硬编码 kwargs["scope"] 为正确的 scope 值。根据 Issue 中用户的测试,这是一种有效的临时解决方案。

  4. 修复 _preflight_authorization_url在调用 create_authorization_url(redirect_uri=redirect_uri) 时,需要同时传递 scope 参数,否则预检检查也会失败。

  5. 确保 resolve_oauth_client_info 正确处理 scope:修改解密后的 blob 重构逻辑,确保 scope 字段不会丢失。如果 blob 是在旧版本创建的,可能需要兼容性处理。

验证方法

重新触发 MCP OAuth 2.1 (Static) 授权流程,检查浏览器发出的 authorize_url 是否包含 scope 参数。如果身份提供者不再返回 AADSTS900144 等 scope 缺失错误,且授权流程顺利完成,则问题解决。

也可以通过启用调试日志观察 client_info.scope 的值是否为有效的 scope 字符串而非 None

参考来源

open-webui/open-webui #25898

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 9593

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注