Skip to content

Commit

Permalink
Merge pull request #27 from extrawest/bugfix/version-endpoints-no-auth
Browse files Browse the repository at this point in the history
[bugfix] Version endpoints no auth support
  • Loading branch information
oleksandr-bozbei-ew authored Dec 1, 2023
2 parents f1ac5bd + 57f9b28 commit 9e59a16
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
29 changes: 29 additions & 0 deletions py_ocpi/core/authentication/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,35 @@ async def __call__(
return await authenticator.authenticate_credentials(token)


class VersionsAuthorizationVerifier(CredentialsAuthorizationVerifier):
"""
A class responsible for verifying authorization tokens
based on the specified version number.
"""

async def __call__(
self,
authorization: str = auth_verifier,
authenticator: Authenticator = Depends(get_authenticator),
) -> str | dict | None:
"""
Verifies the authorization token using the specified version
and an Authenticator for version endpoints.
:param authorization (str): The authorization header containing
the token.
:param authenticator (Authenticator): An Authenticator instance used
for authentication.
:raises AuthorizationOCPIError: If there is an issue with
the authorization token.
"""
if settings.NO_AUTH and authorization == "":
logger.debug("Authentication skipped due to NO_AUTH setting.")
return ""
return await super().__call__(authorization, authenticator)


class HttpPushVerifier:
"""
A class responsible for verifying authorization tokens if using push.
Expand Down
4 changes: 2 additions & 2 deletions py_ocpi/modules/versions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

from py_ocpi.core.authentication.verifier import (
CredentialsAuthorizationVerifier,
VersionsAuthorizationVerifier,
)
from py_ocpi.core import status
from py_ocpi.core.config import logger
Expand All @@ -20,7 +20,7 @@


router = APIRouter()
cred_dependency = CredentialsAuthorizationVerifier(None)
cred_dependency = VersionsAuthorizationVerifier(None)


@router.get("/versions", response_model=OCPIResponse)
Expand Down
4 changes: 2 additions & 2 deletions py_ocpi/modules/versions/v_2_1_1/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

from py_ocpi.core.authentication.verifier import (
CredentialsAuthorizationVerifier,
VersionsAuthorizationVerifier,
)
from py_ocpi.core.crud import Crud
from py_ocpi.core import status
Expand All @@ -21,7 +21,7 @@
)

router = APIRouter()
cred_dependency = CredentialsAuthorizationVerifier(VersionNumber.v_2_1_1)
cred_dependency = VersionsAuthorizationVerifier(VersionNumber.v_2_1_1)


@router.get("/2.1.1/details", response_model=OCPIResponse)
Expand Down
4 changes: 2 additions & 2 deletions py_ocpi/modules/versions/v_2_2_1/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

from py_ocpi.core.authentication.verifier import (
CredentialsAuthorizationVerifier,
VersionsAuthorizationVerifier,
)
from py_ocpi.core.crud import Crud
from py_ocpi.core import status
Expand All @@ -21,7 +21,7 @@
)

router = APIRouter()
cred_dependency = CredentialsAuthorizationVerifier(VersionNumber.v_2_2_1)
cred_dependency = VersionsAuthorizationVerifier(VersionNumber.v_2_2_1)


@router.get("/2.2.1/details", response_model=OCPIResponse)
Expand Down

0 comments on commit 9e59a16

Please sign in to comment.