Skip to content

Commit

Permalink
Merge pull request #11 from icebreakerone/kip/fix-par-input
Browse files Browse the repository at this point in the history
Draft: Fixes #10
  • Loading branch information
kipparker authored Feb 27, 2024
2 parents b93f51f + 2ca8d14 commit 466dec3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
28 changes: 23 additions & 5 deletions authentication/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion authentication/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down

0 comments on commit 466dec3

Please sign in to comment.