mirror of
https://github.com/open-webui/open-webui
synced 2024-12-28 23:02:25 +00:00
feat: refactor signout functionality to use aiohttp for OpenID configuration retrieval
This commit is contained in:
parent
48d604a525
commit
899424b371
@ -3,7 +3,7 @@ import uuid
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import httpx
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
from open_webui.apps.webui.models.auths import (
|
from open_webui.apps.webui.models.auths import (
|
||||||
AddUserForm,
|
AddUserForm,
|
||||||
@ -507,24 +507,25 @@ async def signout(request: Request, response: Response):
|
|||||||
response.delete_cookie("token")
|
response.delete_cookie("token")
|
||||||
|
|
||||||
if ENABLE_OAUTH_SIGNUP.value:
|
if ENABLE_OAUTH_SIGNUP.value:
|
||||||
id_token = request.cookies.get("id_token", None)
|
id_token = request.cookies.get("id_token")
|
||||||
if id_token:
|
if id_token:
|
||||||
async with httpx.AsyncClient() as client:
|
try:
|
||||||
try:
|
async with ClientSession() as session:
|
||||||
openid_config = await client.get(OPENID_PROVIDER_URL.value)
|
async with session.get(OPENID_PROVIDER_URL.value) as resp:
|
||||||
openid_config.raise_for_status()
|
if resp.status == 200:
|
||||||
openid_data = openid_config.json()
|
openid_data = await resp.json()
|
||||||
end_session_endpoint = openid_data.get("end_session_endpoint")
|
logout_url = openid_data.get("end_session_endpoint")
|
||||||
if end_session_endpoint:
|
if logout_url:
|
||||||
logout_url = f"{end_session_endpoint}?id_token_hint={id_token}"
|
response.delete_cookie("id_token")
|
||||||
response.delete_cookie("id_token")
|
return RedirectResponse(url=f"{logout_url}?id_token_hint={id_token}")
|
||||||
return RedirectResponse(url=logout_url)
|
else:
|
||||||
except httpx.HTTPStatusError as e:
|
raise HTTPException(
|
||||||
raise HTTPException(status_code=e.response.status_code, detail="Failed to fetch OpenID configuration")
|
status_code=resp.status,
|
||||||
except Exception as e:
|
detail="Failed to fetch OpenID configuration"
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
# Fall back to the default signout
|
|
||||||
return {"status": True}
|
return {"status": True}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user