chore: Add domain attribute to cookies in login.py and auth.py
This commit is contained in:
parent
a112d72fc1
commit
2a2483d0ee
2 changed files with 8 additions and 0 deletions
|
|
@ -46,6 +46,7 @@ async def login_to_get_access_token(
|
||||||
samesite=auth_settings.REFRESH_SAME_SITE,
|
samesite=auth_settings.REFRESH_SAME_SITE,
|
||||||
secure=auth_settings.REFRESH_SECURE,
|
secure=auth_settings.REFRESH_SECURE,
|
||||||
expires=auth_settings.REFRESH_TOKEN_EXPIRE_SECONDS,
|
expires=auth_settings.REFRESH_TOKEN_EXPIRE_SECONDS,
|
||||||
|
domain=auth_settings.COOKIE_DOMAIN,
|
||||||
)
|
)
|
||||||
response.set_cookie(
|
response.set_cookie(
|
||||||
"access_token_lf",
|
"access_token_lf",
|
||||||
|
|
@ -54,6 +55,7 @@ async def login_to_get_access_token(
|
||||||
samesite=auth_settings.ACCESS_SAME_SITE,
|
samesite=auth_settings.ACCESS_SAME_SITE,
|
||||||
secure=auth_settings.ACCESS_SECURE,
|
secure=auth_settings.ACCESS_SECURE,
|
||||||
expires=auth_settings.ACCESS_TOKEN_EXPIRE_SECONDS,
|
expires=auth_settings.ACCESS_TOKEN_EXPIRE_SECONDS,
|
||||||
|
domain=auth_settings.COOKIE_DOMAIN,
|
||||||
)
|
)
|
||||||
variable_service.initialize_user_variables(user.id, db)
|
variable_service.initialize_user_variables(user.id, db)
|
||||||
# Create default folder for user if it doesn't exist
|
# Create default folder for user if it doesn't exist
|
||||||
|
|
@ -84,6 +86,7 @@ async def auto_login(
|
||||||
samesite=auth_settings.ACCESS_SAME_SITE,
|
samesite=auth_settings.ACCESS_SAME_SITE,
|
||||||
secure=auth_settings.ACCESS_SECURE,
|
secure=auth_settings.ACCESS_SECURE,
|
||||||
expires=None, # Set to None to make it a session cookie
|
expires=None, # Set to None to make it a session cookie
|
||||||
|
domain=auth_settings.COOKIE_DOMAIN,
|
||||||
)
|
)
|
||||||
variable_service.initialize_user_variables(user_id, db)
|
variable_service.initialize_user_variables(user_id, db)
|
||||||
create_default_folder_if_it_doesnt_exist(db, user_id)
|
create_default_folder_if_it_doesnt_exist(db, user_id)
|
||||||
|
|
@ -117,6 +120,7 @@ async def refresh_token(
|
||||||
samesite=auth_settings.REFRESH_SAME_SITE,
|
samesite=auth_settings.REFRESH_SAME_SITE,
|
||||||
secure=auth_settings.REFRESH_SECURE,
|
secure=auth_settings.REFRESH_SECURE,
|
||||||
expires=auth_settings.REFRESH_TOKEN_EXPIRE_SECONDS,
|
expires=auth_settings.REFRESH_TOKEN_EXPIRE_SECONDS,
|
||||||
|
domain=auth_settings.COOKIE_DOMAIN,
|
||||||
)
|
)
|
||||||
response.set_cookie(
|
response.set_cookie(
|
||||||
"access_token_lf",
|
"access_token_lf",
|
||||||
|
|
@ -125,6 +129,7 @@ async def refresh_token(
|
||||||
samesite=auth_settings.ACCESS_SAME_SITE,
|
samesite=auth_settings.ACCESS_SAME_SITE,
|
||||||
secure=auth_settings.ACCESS_SECURE,
|
secure=auth_settings.ACCESS_SECURE,
|
||||||
expires=auth_settings.ACCESS_TOKEN_EXPIRE_SECONDS,
|
expires=auth_settings.ACCESS_TOKEN_EXPIRE_SECONDS,
|
||||||
|
domain=auth_settings.COOKIE_DOMAIN,
|
||||||
)
|
)
|
||||||
return tokens
|
return tokens
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@ class AuthSettings(BaseSettings):
|
||||||
ACCESS_HTTPONLY: bool = False
|
ACCESS_HTTPONLY: bool = False
|
||||||
"""The HttpOnly attribute of the access token cookie."""
|
"""The HttpOnly attribute of the access token cookie."""
|
||||||
|
|
||||||
|
COOKIE_DOMAIN: str | None = None
|
||||||
|
"""The domain attribute of the cookies. If None, the domain is not set."""
|
||||||
|
|
||||||
pwd_context: CryptContext = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
pwd_context: CryptContext = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue