Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace python-jose with pyjwt #1135

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions backend/app/app/api/api_v1/endpoints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from fastapi import (APIRouter, Depends, HTTPException, Request, Response,
status)
from jose import JWTError, jwt
import jwt
from jwt.exceptions import InvalidTokenError
from sqlalchemy.orm import Session

from app.api.deps import get_current_user, get_db
Expand Down Expand Up @@ -104,7 +105,7 @@ async def refresh_token(request: Request, db: Session = Depends(get_db)):
username: str = payload.get("sub")
if username is None:
raise credentials_exception
except JWTError:
except InvalidTokenError:
raise credentials_exception
user = crud.get_user(db, username=username)
if user is None:
Expand Down
5 changes: 3 additions & 2 deletions backend/app/app/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from fastapi import Depends, HTTPException, Security, status
from fastapi.security import OAuth2PasswordBearer
from fastapi.security.api_key import APIKeyCookie, APIKeyHeader, APIKeyQuery
from jose import JWTError, jwt
import jwt
from jwt.exceptions import InvalidTokenError
from sqlalchemy.orm import Session
from starlette.status import HTTP_403_FORBIDDEN

Expand Down Expand Up @@ -68,7 +69,7 @@ async def get_current_user(
if username is None:
raise credentials_exception
token_data = TokenData(username=username)
except JWTError:
except InvalidTokenError:
raise credentials_exception
user = crud.get_user(db, username=token_data.username)
if user is None:
Expand Down
5 changes: 3 additions & 2 deletions backend/app/app/core/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from fastapi import HTTPException, Request, status
from fastapi.staticfiles import StaticFiles
from jose import JWTError, jwt
import jwt
from jwt.exceptions import InvalidTokenError
from passlib.context import CryptContext

from app.api.deps import oauth2_scheme
Expand Down Expand Up @@ -39,7 +40,7 @@ async def verify_token(request: Request):

try:
jwt.decode(token, settings.JWT_SECRET_KEY, algorithms=[settings.JWT_ALGORITHM])
except JWTError as jwt_error:
except InvalidTokenError as jwt_error:
logger.exception(jwt_error)
raise unauthorized

Expand Down
2 changes: 1 addition & 1 deletion backend/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
uvicorn[standard]
fastapi
python-multipart
python-jose[cryptography]
pyjwt[crypto]
passlib[bcrypt]
sqlalchemy
pydantic[dotenv]
Expand Down
Loading