-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
71 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Auth middleware.""" | ||
|
||
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response | ||
from aws_lambda_powertools.event_handler.exceptions import UnauthorizedError | ||
from aws_lambda_powertools.event_handler.middlewares import NextMiddleware | ||
|
||
from aws_packages.auth.exceptions import JWTAuthError | ||
from aws_packages.auth.icp.auth_backend import icp_auth_backend | ||
from aws_packages.auth.models import AuthorizationRequest | ||
|
||
|
||
def icp_login_required( | ||
app: APIGatewayRestResolver, next_middleware: NextMiddleware | ||
) -> Response: | ||
"""Login required middleware | ||
:param app: application instance | ||
:param next_middleware: next middleware | ||
:return: Response object after the middleware has been applied | ||
""" | ||
|
||
request = AuthorizationRequest(**app.current_event.headers) | ||
try: | ||
icp_auth_backend.authenticate_with_token(request.token) | ||
except JWTAuthError: | ||
raise UnauthorizedError(f"Unauthorized") | ||
return next_middleware(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from aws_packages.auth.icp.auth_backend import icp_auth_backend | ||
from aws_packages.auth.views import process_authenticate_request | ||
|
||
|
||
def process_icp_authenticate_request(request_body): | ||
return process_authenticate_request(request_body, icp_auth_backend) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Auth middleware.""" | ||
|
||
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response | ||
from aws_lambda_powertools.event_handler.exceptions import UnauthorizedError | ||
from aws_lambda_powertools.event_handler.middlewares import NextMiddleware | ||
|
||
from aws_packages.auth.exceptions import JWTAuthError | ||
from aws_packages.auth.models import AuthorizationRequest | ||
from aws_packages.auth.solana.auth_backend import solana_auth_backend | ||
|
||
|
||
def solana_login_required( | ||
app: APIGatewayRestResolver, next_middleware: NextMiddleware | ||
) -> Response: | ||
"""Login required middleware | ||
:param app: application instance | ||
:param next_middleware: next middleware | ||
:return: Response object after the middleware has been applied | ||
""" | ||
|
||
request = AuthorizationRequest(**app.current_event.headers) | ||
try: | ||
solana_auth_backend.authenticate_with_token(request.token) | ||
except JWTAuthError: | ||
raise UnauthorizedError(f"Unauthorized") | ||
return next_middleware(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from aws_packages.auth.solana.auth_backend import solana_auth_backend | ||
from aws_packages.auth.views import process_authenticate_request | ||
|
||
|
||
def process_icp_authenticate_request(request_body): | ||
return process_authenticate_request(request_body, solana_auth_backend) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters