use simpler dotenv file
This commit is contained in:
parent
171a94f174
commit
948eb75416
3 changed files with 4 additions and 11 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue