Skip to content

Commit

Permalink
fix the solana proxy auth
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvictor committed Apr 10, 2024
1 parent 7910381 commit 5b17bc6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions aws_packages/auth/auth_backend_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from aws_packages.auth.models import AuthenticationRequest, User

# TODO: use abc abstractmethod


class AuthBackendBase:
"""Base class for authentication backends"""
Expand Down
6 changes: 4 additions & 2 deletions aws_packages/auth/solana/auth_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion aws_packages/auth/solana/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion aws_packages/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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,
Expand Down

0 comments on commit 5b17bc6

Please sign in to comment.