From 623257af766a2c57b620b96dc393a20bfa0b1751 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 3 Nov 2026 22:00:36 +0100 Subject: [PATCH] fix: deprecation warnings when refreshing OAuth tokens with a client secret (#33700) Refreshing an OAuth token, or checking a token's client during token exchange, with the client secret sent over HTTP Basic logged aiohttp deprecation warnings on every call. aiohttp removes the deprecated helper in 4.0, after which these requests would fail. The Authorization header is now built with aiohttp's recommended replacement, and what the provider receives is unchanged. Fixes #33297 --- backend/open_webui/routers/auths.py | 6 ++++-- backend/open_webui/utils/oauth.py | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 318d2dc786..256be9d101 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -10,7 +10,7 @@ import uuid from ssl import CERT_NONE, CERT_REQUIRED, PROTOCOL_TLS import jwt -from aiohttp import BasicAuth, ClientSession +from aiohttp import ClientSession, encode_basic_auth from fastapi import APIRouter, Depends, HTTPException, Request, status from fastapi.responses import JSONResponse, Response from ldap3 import NONE, Connection, Server, Tls @@ -1571,7 +1571,9 @@ async def get_token_client_id(client, token: str) -> str | None: async with session.post( introspection_endpoint, data={'token': token, 'token_type_hint': 'access_token'}, - auth=BasicAuth(client.client_id, client.client_secret or ''), + headers={ + 'Authorization': encode_basic_auth(client.client_id, client.client_secret or '', encoding='latin1') + }, ssl=AIOHTTP_CLIENT_SESSION_SSL, ) as r: if r.status != 200: diff --git a/backend/open_webui/utils/oauth.py b/backend/open_webui/utils/oauth.py index 59023ff75b..a6ff088f1d 100644 --- a/backend/open_webui/utils/oauth.py +++ b/backend/open_webui/utils/oauth.py @@ -1191,10 +1191,12 @@ class OAuthClientManager: if should_send_oauth_resource(client_info): refresh_data['resource'] = client_info.resource - client_auth = None + refresh_headers = {'Content-Type': 'application/x-www-form-urlencoded'} if hasattr(client, 'client_secret') and client.client_secret: if client.client_kwargs.get('token_endpoint_auth_method') == 'client_secret_basic': - client_auth = aiohttp.BasicAuth(client.client_id, client.client_secret) + refresh_headers['Authorization'] = aiohttp.encode_basic_auth( + client.client_id, client.client_secret, encoding='latin1' + ) # Some providers reject a body client_id next to Basic as a second credential (#19415) del refresh_data['client_id'] else: @@ -1213,8 +1215,7 @@ class OAuthClientManager: async with session_http.post( token_endpoint, data=refresh_data, - auth=client_auth, - headers={'Content-Type': 'application/x-www-form-urlencoded'}, + headers=refresh_headers, ssl=AIOHTTP_CLIENT_SESSION_SSL, ) as r: if r.status == 200: @@ -1559,11 +1560,13 @@ class OAuthManager: 'refresh_token': token_data['refresh_token'], 'client_id': client.client_id, } - client_auth = None + refresh_headers = {'Content-Type': 'application/x-www-form-urlencoded'} # Add client_secret if available (some providers require it) if hasattr(client, 'client_secret') and client.client_secret: if client.client_kwargs.get('token_endpoint_auth_method') == 'client_secret_basic': - client_auth = aiohttp.BasicAuth(client.client_id, client.client_secret) + refresh_headers['Authorization'] = aiohttp.encode_basic_auth( + client.client_id, client.client_secret, encoding='latin1' + ) if not OAUTH_ACCESS_TOKEN_REQUEST_INCLUDE_CLIENT_ID: del refresh_data['client_id'] else: @@ -1582,8 +1585,7 @@ class OAuthManager: async with session_http.post( token_endpoint, data=refresh_data, - auth=client_auth, - headers={'Content-Type': 'application/x-www-form-urlencoded'}, + headers=refresh_headers, ssl=AIOHTTP_CLIENT_SESSION_SSL, ) as r: if r.status == 200: