diff --git a/authentication/api/main.py b/authentication/api/main.py index de510b9..8155329 100644 --- a/authentication/api/main.py +++ b/authentication/api/main.py @@ -5,7 +5,7 @@ import requests -from fastapi import FastAPI, Request, Header, HTTPException, Depends, status +from fastapi import FastAPI, Request, Header, HTTPException, Depends, status, Form from fastapi.security import HTTPBasic, OAuth2PasswordRequestForm import datetime @@ -35,21 +35,39 @@ async def test(request: Request) -> dict: # TODO: mock responses from FAPI api using the responses library +# response_type: str +# client_id: int +# redirect_uri: str +# code_challenge: str +# code_challenge_method: str @app.post("/api/v1/par", response_model=models.PushedAuthorizationResponse) async def pushed_authorization_request( - par: models.ClientPushedAuthorizationRequest, + response_type: Annotated[str, Form()], + client_id: Annotated[str, Form()], + redirect_uri: Annotated[str, Form()], + code_challenge: Annotated[str, Form()], + code_challenge_method: Annotated[str, Form()], x_amzn_mtls_clientcert: Annotated[str | None, Header()] = None, ) -> dict: """ Pass the request along to the FAPI api, await the response, send it back to the client app """ - + # Get all arguments and convert to a urlencoded string + encoded_parameters = urllib.parse.urlencode( + { + "response_type": response_type, + "client_id": client_id, + "redirect_uri": redirect_uri, + "code_challenge": code_challenge, + "code_challenge_method": code_challenge_method, + } + ) payload = { - "parameters": urllib.parse.urlencode(par.model_dump()), - "client_id": par.client_id, + "parameters": encoded_parameters, + "client_id": client_id, "client_certificate": x_amzn_mtls_clientcert, } session = requests.Session() diff --git a/authentication/tests/test_api.py b/authentication/tests/test_api.py index b3cd90a..417de86 100644 --- a/authentication/tests/test_api.py +++ b/authentication/tests/test_api.py @@ -30,7 +30,7 @@ def test_pushed_authorization_request(): ) response = client.post( "/api/v1/par", - json={ + data={ "client_id": 123456, "redirect_uri": "https://mobile.example.com/cb", "code_challenge": "W78hCS0q72DfIHa...kgZkEJuAFaT4", diff --git a/client.py b/client.py index b0b7114..04cf854 100644 --- a/client.py +++ b/client.py @@ -11,6 +11,7 @@ AUTHENTICATION_API = os.environ.get("AUTHENTICATION_API", "https://0.0.0.0:8000") RESOURCE_API = os.environ.get("RESOURCE_API", "https://0.0.0.0:8010") + ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) CLIENT_CERTIFICATE = f"{ROOT_PATH}/certs/client-cert.pem" CLIENT_PRIVATE_KEY = f"{ROOT_PATH}/certs/client-key.pem" @@ -27,7 +28,7 @@ def pushed_authorization_request(): response = requests.post( f"{AUTHENTICATION_API}/api/v1/par", - json={ + data={ "response_type": "code", "client_id": f"{conf.CLIENT_ID}", "redirect_uri": "https://mobile.example.com/cb",