mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac: auth endpoint
This commit is contained in:
parent
2a4dfc02a2
commit
62e57a4cf5
@ -82,28 +82,31 @@ async def get_session_user(
|
|||||||
token = auth_token.credentials
|
token = auth_token.credentials
|
||||||
data = decode_token(token)
|
data = decode_token(token)
|
||||||
|
|
||||||
expires_at = data.get("exp")
|
expires_at = None
|
||||||
|
|
||||||
if (expires_at is not None) and int(time.time()) > expires_at:
|
if data:
|
||||||
raise HTTPException(
|
expires_at = data.get("exp")
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
||||||
detail=ERROR_MESSAGES.INVALID_TOKEN,
|
if (expires_at is not None) and 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,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user