mirror of
https://git.mirrors.martin98.com/https://github.com/open-webui/open-webui
synced 2025-08-18 02:25:51 +08:00
fix: token cookie issue
This commit is contained in:
parent
fb1c101dc6
commit
45ad6776de
@ -84,6 +84,26 @@ async def get_session_user(
|
|||||||
data = decode_token(token)
|
data = decode_token(token)
|
||||||
expires_at = data.get("exp")
|
expires_at = data.get("exp")
|
||||||
|
|
||||||
|
if int(time.time()) > expires_at:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail=ERROR_MESSAGES.INVALID_TOKEN,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set the cookie token
|
||||||
|
response.set_cookie(
|
||||||
|
key="token",
|
||||||
|
value=token,
|
||||||
|
expires=(
|
||||||
|
datetime.datetime.fromtimestamp(expires_at, datetime.timezone.utc)
|
||||||
|
if expires_at
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
httponly=True, # Ensures the cookie is not accessible via JavaScript
|
||||||
|
samesite=WEBUI_AUTH_COOKIE_SAME_SITE,
|
||||||
|
secure=WEBUI_AUTH_COOKIE_SECURE,
|
||||||
|
)
|
||||||
|
|
||||||
user_permissions = get_permissions(
|
user_permissions = get_permissions(
|
||||||
user.id, request.app.state.config.USER_PERMISSIONS
|
user.id, request.app.state.config.USER_PERMISSIONS
|
||||||
)
|
)
|
||||||
@ -288,6 +308,13 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|||||||
response.set_cookie(
|
response.set_cookie(
|
||||||
key="token",
|
key="token",
|
||||||
value=token,
|
value=token,
|
||||||
|
expires=(
|
||||||
|
datetime.datetime.fromtimestamp(
|
||||||
|
expires_at, datetime.timezone.utc
|
||||||
|
)
|
||||||
|
if expires_at
|
||||||
|
else None
|
||||||
|
),
|
||||||
httponly=True, # Ensures the cookie is not accessible via JavaScript
|
httponly=True, # Ensures the cookie is not accessible via JavaScript
|
||||||
samesite=WEBUI_AUTH_COOKIE_SAME_SITE,
|
samesite=WEBUI_AUTH_COOKIE_SAME_SITE,
|
||||||
secure=WEBUI_AUTH_COOKIE_SECURE,
|
secure=WEBUI_AUTH_COOKIE_SECURE,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user