add creation refresh token

This commit is contained in:
IluaAir
2025-09-20 21:54:28 +03:00
parent 9099120ee2
commit 8620e9b5a1
2 changed files with 17 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
import os
from datetime import datetime, timedelta, timezone
import bcrypt
import jwt
from passlib.context import CryptContext
@@ -34,6 +36,13 @@ class AuthManager:
)
return encoded_jwt
@classmethod
def create_refresh_token(cls) -> str:
random_bytes = os.urandom(32)
data = b'settings.refresh_token.secret_key' + random_bytes
token_hash = bcrypt.hashpw(data, bcrypt.gensalt(rounds=12)).decode()
return token_hash
@classmethod
def decode_access_token(cls, token: str) -> dict:
return jwt.decode(

View File

@@ -40,10 +40,18 @@ class AccessToken(BaseSettings):
token_type: str = "bearer" # noqa: S105
class RefreshToken(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env", env_file_encoding="utf-8", env_prefix="REFRESH_TOKEN_"
)
secret_key: str
class Settings(BaseSettings):
api: ApiPrefix = ApiPrefix()
db: DbSettings = DbSettings()
access_token: AccessToken = AccessToken() # type: ignore
refresh_token: RefreshToken = RefreshToken() # type: ignore
settings = Settings()