This repository was archived by the owner on Jan 7, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 13
13
from pydantic import BaseModel
14
14
from sqlalchemy import select
15
15
16
+ import dotenv
17
+ dotenv .load_dotenv ()
18
+
16
19
import api .schemas as schemas
17
20
import api .database as db
18
21
19
- # to get a string like this run:
20
- # openssl rand -hex 32
21
- SECRET_KEY = "11937be5daeb452985fc2d4f8ab09841d2fa45f48d72960b470d52fd84f4088e"
22
+
22
23
ALGORITHM = "HS256"
23
24
ACCESS_TOKEN_EXPIRE_MINUTES = 60
24
25
@@ -111,7 +112,7 @@ async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]):
111
112
headers = {"WWW-Authenticate" : "Bearer" },
112
113
)
113
114
try :
114
- payload = jwt .decode (token , SECRET_KEY , algorithms = [ALGORITHM ])
115
+ payload = jwt .decode (token , os . environ [ ' SECRET_KEY' ] , algorithms = [os . environ [ 'JWT_ENCRYPTION_ALGORITHM' ] ])
115
116
sub : str = payload .get ("sub" )
116
117
if sub is None :
117
118
raise credentials_exception
@@ -131,7 +132,7 @@ def create_access_token(data: dict, expires_delta: timedelta | None = None):
131
132
else :
132
133
expire = datetime .utcnow () + timedelta (minutes = 15 )
133
134
to_encode .update ({"exp" : expire })
134
- encoded_jwt = jwt .encode (to_encode , SECRET_KEY , algorithm = ALGORITHM )
135
+ encoded_jwt = jwt .encode (to_encode , os . environ [ ' SECRET_KEY' ] , algorithm = os . environ [ 'JWT_ENCRYPTION_ALGORITHM' ] )
135
136
return encoded_jwt
136
137
137
138
You can’t perform that action at this time.
0 commit comments