From 905e3b680e289717dbad275b4f0f3ba3d17c0574 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Thu, 7 Apr 2022 20:56:09 +0200 Subject: [PATCH] :recycle: Removed an unnecessary duplicate --- classquiz/auth.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/classquiz/auth.py b/classquiz/auth.py index 0813aae..2ae8568 100644 --- a/classquiz/auth.py +++ b/classquiz/auth.py @@ -16,6 +16,7 @@ from passlib.hash import argon2 from classquiz.cache import get_cache from classquiz.config import settings from classquiz.db.models import * + settings = settings() # pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") @@ -96,12 +97,14 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None): return encoded_jwt +credentials_exception = HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Could not validate credentials", + headers={"WWW-Authenticate": "Bearer"}, +) + + async def get_current_user(token: str = Depends(oauth2_scheme)): - credentials_exception = HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail="Could not validate credentials", - headers={"WWW-Authenticate": "Bearer"}, - ) try: payload = jwt.decode(token, settings.secret_key, algorithms=[ALGORITHM]) email: str = payload.get("sub") @@ -132,11 +135,6 @@ async def get_current_user_optional(token: str = Depends(oauth2_scheme)) -> User async def check_token(token: str = Depends(oauth2_scheme)): - credentials_exception = HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail="Could not validate credentials", - headers={"WWW-Authenticate": "Bearer"}, - ) try: payload = jwt.decode(token, settings.secret_key, algorithms=[ALGORITHM]) email: str = payload.get("sub")