Skip to content

Commit 7930bc2

Browse files
committed
Sanitize code snippets
1 parent 5f3d33a commit 7930bc2

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

demo/dependencies.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
from typing import Optional
22

3-
from fastapi import Depends, HTTPException
3+
from fastapi import HTTPException
44
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
55
from fastapi.security import OAuth2
66
from fastapi.security.utils import get_authorization_scheme_param
7-
from jose import JWTError
87
from starlette.requests import Request
98
from starlette.status import HTTP_403_FORBIDDEN
109

11-
from fastapi_oauth2.utils import jwt_decode
12-
1310

1411
class OAuth2PasswordBearerCookie(OAuth2):
1512
def __init__(
@@ -40,12 +37,3 @@ async def __call__(self, request: Request) -> Optional[str]:
4037

4138

4239
oauth2_scheme = OAuth2PasswordBearerCookie(tokenUrl="/token")
43-
44-
45-
async def get_current_user(token: str = Depends(oauth2_scheme)):
46-
try:
47-
return jwt_decode(token)
48-
except JWTError:
49-
raise HTTPException(
50-
status_code=HTTP_403_FORBIDDEN, detail="Could not validate credentials"
51-
)

demo/router.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
from fastapi import Depends
33
from starlette.requests import Request
44

5-
from .dependencies import get_current_user
5+
from .dependencies import oauth2_scheme
66

77
router = APIRouter()
88

99

1010
@router.get("/user")
11-
def user(current_user=Depends(get_current_user)):
12-
return current_user
11+
def user(request: Request, _: str = Depends(oauth2_scheme)):
12+
return request.user
1313

1414

1515
@router.post("/token")

src/fastapi_oauth2/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Optional, Type, Sequence
1+
from typing import Optional
2+
from typing import Sequence
3+
from typing import Type
24

35
from social_core.backends.oauth import BaseOAuth2
46

0 commit comments

Comments
 (0)