add creation refresh token
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import bcrypt
|
||||
import jwt
|
||||
from passlib.context import CryptContext
|
||||
|
||||
@@ -33,6 +35,13 @@ class AuthManager:
|
||||
algorithm=settings.access_token.algorithm,
|
||||
)
|
||||
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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user