mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 02:48:13 -05:00
[PR #22359] [MERGED] fix: add support for scope in OAuth refresh token request #26630
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/22359
Author: @pedro-inf-custodio
Created: 3/7/2026
Status: ✅ Merged
Merged: 3/8/2026
Merged by: @tjbck
Base:
dev← Head:fix/add-scope-refresh-token-oauth📝 Commits (6)
416597afix: add support for scope in OAuth refresh token request6b93e33add oauth refresh token include scopeb9cca4bFix variable importa461157Fix env variables importefd7ac9Added debug logs WIP781333eRemove debug logs📊 Changes
2 files changed (+28 additions, -0 deletions)
View changed files
📝
backend/open_webui/config.py(+6 -0)📝
backend/open_webui/utils/oauth.py(+22 -0)📄 Description
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.
Description
This PR fixes an issue where the refresh token request for Microsoft OAuth was failing with error
AADSTS90009. Previously, the refresh payload only included thegrant_type,refresh_token,client_id, and optionallyclient_secret.Azure AD requires the scope (or resource) to be explicitly provided when refreshing a token. Without it, Azure interprets the request as “the application is requesting a token for itself,” which triggers the 400 error:
Changes
MICROSOFT_OAUTH_SCOPE._perform_token_refreshto include this scope when refreshing tokens.Root Cause
scopecaused Azure to treat the request as self-targeted, resulting inAADSTS90009.Logs Before Fix
Logs After Fix
Environment Variables
MICROSOFT_OAUTH_SCOPE(required) – the custom scope for token requests.Optional Configuration (Potential Follow-up)
As a potential follow-up improvement, it may also be possible to control this behavior via an environment variable, if maintainers consider this a suitable approach:
OAUTH_REFRESH_TOKEN_INCLUDE_SCOPE=false # defaultThis would allow enabling or disabling the inclusion of the
scopeparameter in refresh token requests.This approach remains compliant with RFC 6749 Section 6, where the
scopeparameter is optional during refresh token requests and typically omitted unless required by the OAuth provider.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.