diff --git a/auth/models.py b/auth/models.py index 8a86691..c137064 100644 --- a/auth/models.py +++ b/auth/models.py @@ -6,6 +6,7 @@ from pydantic import BaseModel from fastapi import Depends, HTTPException from typing import Annotated, Optional from fastapi.security import OAuth2PasswordBearer +from passlib.context import CryptContext import jwt from sqlmodel import SQLModel, Field, Session, select from pydantic.networks import EmailStr @@ -93,7 +94,7 @@ def create_access_token( to_encode = data.copy() expire = datetime.now(timezone.utc) + expires_delta to_encode.update({"exp": expire}) - encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) + encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm="HS256") return encoded_jwt @@ -118,7 +119,7 @@ async def get_current_user( headers={"WWW-Authenticate": "Bearer"}, ) try: - payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) + payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"]) token_data = TokenData(**payload) username: Optional[str] = payload.get("sub") if username is None: diff --git a/auth/router.py b/auth/router.py index 2e1a25d..462da69 100644 --- a/auth/router.py +++ b/auth/router.py @@ -49,7 +49,7 @@ async def login_for_access_token( detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, ) - access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) + access_token_expires = timedelta(minutes=30) access_token = create_access_token( data={"sub": user.username, "role": user.role, 'status': user.status}, expires_delta=access_token_expires ) diff --git a/config.py b/config.py index b2fcaf3..07d6e59 100644 --- a/config.py +++ b/config.py @@ -29,15 +29,7 @@ def get_session_db(): yield session - ### SECRET KEY ### -SECRET_KEY = os.getenv("SECRET_KEY") -ALGORITHM = os.getenv("ALGORITHM") -ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES")) - - -pwd_context = CryptContext(schemes=[f"{os.getenv('CRYPTO_TYPE')}"], deprecated="auto") - origins = [ "http://localhost", "http://localhost:8080",