diff --git a/Cargo.toml b/Cargo.toml index 5a917e6..0be002a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws_packages" -version = "0.0.16" +version = "0.0.17" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/aws_packages/auth/auth_backend_base.py b/aws_packages/auth/auth_backend_base.py index ac0425f..3fca268 100644 --- a/aws_packages/auth/auth_backend_base.py +++ b/aws_packages/auth/auth_backend_base.py @@ -1,5 +1,7 @@ from aws_packages.auth.models import AuthenticationRequest, User +# TODO: use abc abstractmethod + class AuthBackendBase: """Base class for authentication backends""" diff --git a/aws_packages/auth/solana/auth_backend.py b/aws_packages/auth/solana/auth_backend.py index 60dd394..5b07131 100644 --- a/aws_packages/auth/solana/auth_backend.py +++ b/aws_packages/auth/solana/auth_backend.py @@ -13,12 +13,14 @@ class SolanaAuthBackend(AuthBackendBase): def __init__(self, url: str): self._url = url - def authenticate(self, login_request: AuthenticationRequest) -> User: + def authenticate(self, login_request_body: AuthenticationRequest) -> User: """Authenticate the request and returns an authenticated User""" # solana sdk call and authenticate or raise exception + if login_request_body.authcode != "1234": + raise Exception("Invalid authcode") - return User(principal=login_request.user) + return User(principal=login_request_body.user) def authenticate_with_token(self, token: str): """Authenticate user using jwt token and return status""" diff --git a/aws_packages/auth/solana/views.py b/aws_packages/auth/solana/views.py index 2eae7e8..e01d58b 100644 --- a/aws_packages/auth/solana/views.py +++ b/aws_packages/auth/solana/views.py @@ -2,5 +2,5 @@ from aws_packages.auth.views import process_authenticate_request -def process_icp_authenticate_request(request_body): +def process_solana_authenticate_request(request_body): return process_authenticate_request(request_body, solana_auth_backend) diff --git a/aws_packages/auth/views.py b/aws_packages/auth/views.py index ac2137a..ae8fa5a 100644 --- a/aws_packages/auth/views.py +++ b/aws_packages/auth/views.py @@ -4,10 +4,11 @@ from aws_lambda_powertools.event_handler import Response, content_types from aws_lambda_powertools.event_handler.exceptions import BadRequestError +from aws_packages.auth.auth_backend_base import AuthBackendBase from aws_packages.auth.models import AuthenticationRequest, LoginResponse -def process_authenticate_request(request_body, auth_backend): +def process_authenticate_request(request_body, auth_backend: AuthBackendBase): if request_body is None: raise BadRequestError("No request body provided") @@ -16,6 +17,7 @@ def process_authenticate_request(request_body, auth_backend): try: auth_user = auth_backend.authenticate(request_obj) except Exception as e: + # TODO: Raise error instead of response return Response( status_code=HTTPStatus.BAD_REQUEST.value, content_type=content_types.APPLICATION_JSON,