mirror of
https://git.mirrors.martin98.com/https://github.com/open-webui/open-webui
synced 2025-08-18 05:56:01 +08:00
refac/fix: signout redirect flow
This commit is contained in:
parent
fcb93f3155
commit
7df6d7f325
@ -31,7 +31,7 @@ from open_webui.env import (
|
|||||||
SRC_LOG_LEVELS,
|
SRC_LOG_LEVELS,
|
||||||
)
|
)
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||||
from fastapi.responses import RedirectResponse, Response
|
from fastapi.responses import RedirectResponse, Response, JSONResponse
|
||||||
from open_webui.config import OPENID_PROVIDER_URL, ENABLE_OAUTH_SIGNUP, ENABLE_LDAP
|
from open_webui.config import OPENID_PROVIDER_URL, ENABLE_OAUTH_SIGNUP, ENABLE_LDAP
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@ -577,9 +577,14 @@ async def signout(request: Request, response: Response):
|
|||||||
logout_url = openid_data.get("end_session_endpoint")
|
logout_url = openid_data.get("end_session_endpoint")
|
||||||
if logout_url:
|
if logout_url:
|
||||||
response.delete_cookie("oauth_id_token")
|
response.delete_cookie("oauth_id_token")
|
||||||
return RedirectResponse(
|
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=200,
|
||||||
|
content={
|
||||||
|
"status": True,
|
||||||
|
"redirect_url": f"{logout_url}?id_token_hint={oauth_id_token}",
|
||||||
|
},
|
||||||
headers=response.headers,
|
headers=response.headers,
|
||||||
url=f"{logout_url}?id_token_hint={oauth_id_token}",
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@ -594,12 +599,18 @@ async def signout(request: Request, response: Response):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if WEBUI_AUTH_SIGNOUT_REDIRECT_URL:
|
if WEBUI_AUTH_SIGNOUT_REDIRECT_URL:
|
||||||
return RedirectResponse(
|
return JSONResponse(
|
||||||
|
status_code=200,
|
||||||
|
content={
|
||||||
|
"status": True,
|
||||||
|
"redirect_url": WEBUI_AUTH_SIGNOUT_REDIRECT_URL,
|
||||||
|
},
|
||||||
headers=response.headers,
|
headers=response.headers,
|
||||||
url=WEBUI_AUTH_SIGNOUT_REDIRECT_URL,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"status": True}
|
return JSONResponse(
|
||||||
|
status_code=200, content={"status": True}, headers=response.headers
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
############################
|
############################
|
||||||
|
@ -347,6 +347,7 @@ export const userSignOut = async () => {
|
|||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addUser = async (
|
export const addUser = async (
|
||||||
|
@ -156,12 +156,11 @@
|
|||||||
<button
|
<button
|
||||||
class="flex rounded-md py-2 px-3 w-full hover:bg-gray-50 dark:hover:bg-gray-800 transition"
|
class="flex rounded-md py-2 px-3 w-full hover:bg-gray-50 dark:hover:bg-gray-800 transition"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
await userSignOut();
|
const res = await userSignOut();
|
||||||
user.set(null);
|
user.set(null);
|
||||||
|
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
location.href = '/auth';
|
|
||||||
|
|
||||||
|
location.href = res?.redirect_url ?? '/auth';
|
||||||
show = false;
|
show = false;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -464,11 +464,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (now >= exp) {
|
if (now >= exp) {
|
||||||
await userSignOut();
|
const res = await userSignOut();
|
||||||
user.set(null);
|
user.set(null);
|
||||||
|
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
location.href = '/auth';
|
|
||||||
|
location.href = res?.redirect_url ?? '/auth';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user