mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
Add refresh token auth routes and utilities
This commit is contained in:
parent
9bd7d74755
commit
f3a9922eb9
8 changed files with 431 additions and 125 deletions
29
surfsense_backend/app/utils/auth_cookies.py
Normal file
29
surfsense_backend/app/utils/auth_cookies.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"""Utilities for managing authentication cookies."""
|
||||
|
||||
from fastapi import Response
|
||||
|
||||
from app.config import config
|
||||
|
||||
REFRESH_TOKEN_COOKIE_NAME = "refresh_token"
|
||||
|
||||
|
||||
def set_refresh_token_cookie(response: Response, token: str) -> None:
|
||||
"""Set the refresh token as an HTTP-only cookie."""
|
||||
response.set_cookie(
|
||||
key=REFRESH_TOKEN_COOKIE_NAME,
|
||||
value=token,
|
||||
max_age=config.REFRESH_TOKEN_LIFETIME_SECONDS,
|
||||
httponly=True,
|
||||
secure=True, # Only send over HTTPS
|
||||
samesite="lax",
|
||||
)
|
||||
|
||||
|
||||
def delete_refresh_token_cookie(response: Response) -> None:
|
||||
"""Delete the refresh token cookie."""
|
||||
response.delete_cookie(
|
||||
key=REFRESH_TOKEN_COOKIE_NAME,
|
||||
httponly=True,
|
||||
secure=True,
|
||||
samesite="lax",
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue