add integration
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from http import HTTPStatus
|
||||
from pathlib import Path
|
||||
from typing import Annotated
|
||||
|
||||
from aws_lambda_powertools.event_handler import (
|
||||
@@ -7,8 +6,9 @@ from aws_lambda_powertools.event_handler import (
|
||||
)
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from aws_lambda_powertools.event_handler.exceptions import ForbiddenError, NotFoundError
|
||||
from aws_lambda_powertools.event_handler.openapi.params import Form
|
||||
from aws_lambda_powertools.event_handler.openapi.params import Form, Param
|
||||
from aws_lambda_powertools.shared.cookies import Cookie
|
||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
from passlib.hash import pbkdf2_sha256
|
||||
|
||||
@@ -18,15 +18,20 @@ from jose_ import generate_jwt
|
||||
|
||||
router = Router()
|
||||
oauth2_layer = DynamoDBPersistenceLayer(OAUTH2_TABLE, dynamodb_client)
|
||||
templates = Environment(
|
||||
loader=PackageLoader('app'),
|
||||
autoescape=select_autoescape(['html']),
|
||||
)
|
||||
|
||||
|
||||
@router.get('/login')
|
||||
def login_form():
|
||||
html = Path(__file__).with_name('login.html').read_text(encoding='utf-8')
|
||||
@router.get('/login', compress=True)
|
||||
def login_form(continue_: Annotated[str, Param(alias='continue')]):
|
||||
template = templates.get_template('login.html')
|
||||
html = template.render(**{'continue': continue_})
|
||||
|
||||
return Response(
|
||||
body=html,
|
||||
status_code=HTTPStatus.OK.value,
|
||||
status_code=HTTPStatus.OK,
|
||||
content_type='text/html',
|
||||
)
|
||||
|
||||
@@ -35,6 +40,7 @@ def login_form():
|
||||
def login(
|
||||
username: Annotated[str, Form()],
|
||||
password: Annotated[str, Form()],
|
||||
continue_: Annotated[str, Form(alias='continue')],
|
||||
):
|
||||
user_id, password_hash = _get_user(username)
|
||||
|
||||
@@ -44,7 +50,10 @@ def login(
|
||||
jwt_token = generate_jwt(user_id, username)
|
||||
|
||||
return Response(
|
||||
status_code=HTTPStatus.OK,
|
||||
status_code=HTTPStatus.FOUND,
|
||||
headers={
|
||||
'Location': continue_,
|
||||
},
|
||||
cookies=[
|
||||
Cookie(
|
||||
name='id_token',
|
||||
|
||||
Reference in New Issue
Block a user