feat: oauth 2.1 static mcp
Co-Authored-By: Joost Mul <6438009+donmul@users.noreply.github.com>
This commit is contained in:
co-authored by
Joost Mul
parent
631bd20c35
commit
601bb78358
@@ -24,6 +24,7 @@ from open_webui.models.oauth_sessions import OAuthSessions
|
||||
from open_webui.utils.oauth import (
|
||||
get_discovery_urls,
|
||||
get_oauth_client_info_with_dynamic_client_registration,
|
||||
get_oauth_client_info_with_static_credentials,
|
||||
encrypt_data,
|
||||
decrypt_data,
|
||||
OAuthClientInformationFull,
|
||||
@@ -99,6 +100,7 @@ class OAuthClientRegistrationForm(BaseModel):
|
||||
url: str
|
||||
client_id: str
|
||||
client_name: Optional[str] = None
|
||||
client_secret: Optional[str] = None
|
||||
|
||||
|
||||
@router.post('/oauth/clients/register')
|
||||
@@ -113,9 +115,19 @@ async def register_oauth_client(
|
||||
if type:
|
||||
oauth_client_id = f'{type}:{form_data.client_id}'
|
||||
|
||||
oauth_client_info = await get_oauth_client_info_with_dynamic_client_registration(
|
||||
request, oauth_client_id, form_data.url
|
||||
)
|
||||
if form_data.client_secret:
|
||||
# Static credentials: skip dynamic registration, build from provided credentials
|
||||
oauth_client_info = await get_oauth_client_info_with_static_credentials(
|
||||
request,
|
||||
oauth_client_id,
|
||||
form_data.url,
|
||||
oauth_client_id=form_data.client_id,
|
||||
oauth_client_secret=form_data.client_secret,
|
||||
)
|
||||
else:
|
||||
oauth_client_info = await get_oauth_client_info_with_dynamic_client_registration(
|
||||
request, oauth_client_id, form_data.url
|
||||
)
|
||||
return {
|
||||
'status': True,
|
||||
'oauth_client_info': encrypt_data(oauth_client_info.model_dump(mode='json')),
|
||||
@@ -166,7 +178,7 @@ async def set_tool_servers_config(
|
||||
server_type = connection.get('type', 'openapi')
|
||||
auth_type = connection.get('auth_type', 'none')
|
||||
|
||||
if auth_type == 'oauth_2.1':
|
||||
if auth_type in ('oauth_2.1', 'oauth_2.1_static'):
|
||||
# Remove existing OAuth clients for tool servers
|
||||
server_id = connection.get('info', {}).get('id')
|
||||
client_key = f'{server_type}:{server_id}'
|
||||
@@ -189,7 +201,7 @@ async def set_tool_servers_config(
|
||||
server_id = connection.get('info', {}).get('id')
|
||||
auth_type = connection.get('auth_type', 'none')
|
||||
|
||||
if auth_type == 'oauth_2.1' and server_id:
|
||||
if auth_type in ('oauth_2.1', 'oauth_2.1_static') and server_id:
|
||||
try:
|
||||
oauth_client_info = connection.get('info', {}).get('oauth_client_info', '')
|
||||
oauth_client_info = decrypt_data(oauth_client_info)
|
||||
@@ -264,7 +276,7 @@ async def verify_tool_servers_config(request: Request, form_data: ToolServerConn
|
||||
"""
|
||||
try:
|
||||
if form_data.type == 'mcp':
|
||||
if form_data.auth_type == 'oauth_2.1':
|
||||
if form_data.auth_type in ('oauth_2.1', 'oauth_2.1_static'):
|
||||
discovery_urls = await get_discovery_urls(form_data.url)
|
||||
for discovery_url in discovery_urls:
|
||||
log.debug(f'Trying to fetch OAuth 2.1 discovery document from {discovery_url}')
|
||||
|
||||
Reference in New Issue
Block a user