Skip to content

Commit

Permalink
Fix typeguard check
Browse files Browse the repository at this point in the history
  • Loading branch information
francbartoli committed Apr 29, 2024
1 parent b477f52 commit 8e88bc5
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 126 deletions.
4 changes: 2 additions & 2 deletions app/auth/auth_jwks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ async def decode_token(
async def authenticate(
self,
request: Request,
accepted_methods: typing.Optional[typing.List[str]] = ["access_token"], # noqa
accepted_methods: typing.List[str] = ["access_token"], # noqa
) -> typing.Union[RedirectResponse, typing.Dict]:
"""Authenticate the caller with the incoming request."""
bearer = request.headers.get("Authorization")
if not bearer:
logger.exception("Unable to get a token")
raise Oauth2Error("Auth token not found")
raise Oauth2Error("Auth token not found in the incoming request")
access_token = bearer.replace("Bearer ", "")
try:
claims = await self.decode_token(access_token)
Expand Down
7 changes: 4 additions & 3 deletions app/auth/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from abc import abstractmethod
from typing import List
from typing import Optional
from typing import Union

from starlette.requests import Request

Expand Down Expand Up @@ -34,9 +35,9 @@ class Oauth2Provider:

def __init__(
self,
authentication: [AuthInterface, List[AuthInterface]], # type:ignore
authentication: Union[AuthInterface, List[AuthInterface]],
injectables: Optional[List[Injectable]] = None,
accepted_methods: Optional[List[str]] = [ # noqa B006
accepted_methods: List[str] = [ # noqa B006
"id_token",
"access_token",
],
Expand All @@ -46,7 +47,7 @@ def __init__(
PARAMETERS
----------
authentication: [AuthInterface, List[AuthInterface]]
Authentication Implementations to be used for the
Authentication implementations to be used for the
request authentication.
injectables: List[Injectable], default=None
List of injectables to be used to add information to the
Expand Down
4 changes: 1 addition & 3 deletions app/middleware/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
successful = False
for auth in self.config.authentication:
try:
user_info_or_auth_redirect = auth.authenticate(
request, self.config.accepted_methods
)
user_info_or_auth_redirect = auth.authenticate(request)
if asyncio.iscoroutine(user_info_or_auth_redirect):
user_info_or_auth_redirect = await user_info_or_auth_redirect
logger.debug(
Expand Down
Loading

0 comments on commit 8e88bc5

Please sign in to comment.