fix auth manager
This commit is contained in:
35
src/core/auth_manager.py
Normal file
35
src/core/auth_manager.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from datetime import timedelta, datetime, timezone
|
||||
|
||||
import jwt
|
||||
from passlib.context import CryptContext
|
||||
|
||||
from src.core.settings import settings
|
||||
|
||||
|
||||
class AuthManger:
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
|
||||
@classmethod
|
||||
def verify_password(cls, plain_password, hashed_password):
|
||||
return cls.pwd_context.verify(plain_password, hashed_password)
|
||||
|
||||
@classmethod
|
||||
def get_password_hash(cls, password):
|
||||
return cls.pwd_context.hash(password)
|
||||
|
||||
@classmethod
|
||||
def create_access_token(cls, data: dict, expires_delta: timedelta | None = None):
|
||||
to_encode = data.copy()
|
||||
if expires_delta:
|
||||
expire = datetime.now(timezone.utc) + expires_delta
|
||||
else:
|
||||
expire = datetime.now(timezone.utc) + timedelta(
|
||||
minutes=settings.access_token.expire_minutes
|
||||
)
|
||||
to_encode.update({"exp": expire})
|
||||
encoded_jwt = jwt.encode(
|
||||
to_encode,
|
||||
settings.access_token.secret_key,
|
||||
algorithm=settings.access_token.algorithm,
|
||||
)
|
||||
return encoded_jwt
|
||||
Reference in New Issue
Block a user