22from typing import Annotated , Union
33
44import jwt
5+ from api .config import Config
56from api .database .models .users import User
67from api .exceptions .http_exceptions import CredentialsException
78from api .schemas .auth import TokenData
1314oauth2_scheme = OAuth2PasswordBearer (tokenUrl = "/auth/token" )
1415
1516
16- SECRET_KEY = "ef555b4c8637c33623fe8e91ba7256725e7e2a1bcc75fe84acb189bcaa6c8693"
17- ALGORITHM = "HS256"
18- ACCESS_TOKEN_EXPIRE_MINUTES = 30
19-
20-
2117class AuthService :
2218 @staticmethod
2319 def verify_password (plain_password , hashed_password ):
@@ -42,16 +38,20 @@ def create_access_token(
4238 ):
4339 to_encode = data .copy ()
4440 expires_at = datetime .now (timezone .utc ) + timedelta (
45- minutes = expires_delta_in_minutes or ACCESS_TOKEN_EXPIRE_MINUTES
41+ minutes = expires_delta_in_minutes or Config . AUTH . ACCESS_TOKEN_EXPIRE_MINUTES
4642 )
4743 to_encode .update ({"exp" : expires_at })
48- encoded_jwt = jwt .encode (to_encode , SECRET_KEY , algorithm = ALGORITHM )
44+ encoded_jwt = jwt .encode (
45+ to_encode , Config .AUTH .SECRET_KEY , algorithm = Config .AUTH .ALGORITHM
46+ )
4947 return encoded_jwt , expires_at
5048
5149 # @staticmethod
5250 async def get_current_user (token : Annotated [str , Depends (oauth2_scheme )]):
5351 try :
54- payload = jwt .decode (token , SECRET_KEY , algorithms = [ALGORITHM ])
52+ payload = jwt .decode (
53+ token , Config .AUTH .SECRET_KEY , algorithms = [Config .AUTH .ALGORITHM ]
54+ )
5555 username : Union [str , None ] = payload .get ("sub" )
5656 if username is None :
5757 raise CredentialsException ()
0 commit comments