Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/auth0/authentication/pushed_authorization_requests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Any

from .base import AuthenticationBase
Expand All @@ -22,6 +23,11 @@ def pushed_authorization_request(

See: https://www.rfc-editor.org/rfc/rfc9126.html
"""
if isinstance(kwargs.get("authorization_details"), list):
kwargs["authorization_details"] = json.dumps(
kwargs["authorization_details"]
)

return self.authenticated_post(
f"{self.protocol}://{self.domain}/oauth/par",
data={
Expand Down
23 changes: 22 additions & 1 deletion tests/authentication/test_pushed_authorization_requests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import json
from unittest import mock
from urllib.parse import parse_qs

from auth0.authentication.pushed_authorization_requests import PushedAuthorizationRequests

Expand Down Expand Up @@ -63,7 +64,7 @@ def test_with_authorization_details(self, mock_post):
"client_secret": "sh!",
"response_type": "code",
"redirect_uri": "https://example.com/callback",
"authorization_details": [{"type": "money_transfer", "instructedAmount": {"amount": 2500, "currency": "USD"}}],
"authorization_details": json.dumps([{"type": "money_transfer", "instructedAmount": {"amount": 2500, "currency": "USD"}}]),
}

actual_data = kwargs["data"]
Expand All @@ -75,6 +76,26 @@ def test_with_authorization_details(self, mock_post):
json.dumps(expected_data, sort_keys=True)
)

@mock.patch("requests.request")
def test_authorization_details_sent_as_json(self, mock_requests_request):
response = mock.MagicMock()
response.status_code = 201
response.text = '{"request_uri": "urn:example", "expires_in": 30}'
mock_requests_request.return_value = response

authorization_details = [{"type": "money_transfer", "instructedAmount": {"amount": 2500, "currency": "USD"}}]
a = PushedAuthorizationRequests("my.domain.com", "cid", client_secret="sh!")
a.pushed_authorization_request(
response_type="code",
redirect_uri="https://example.com/callback",
authorization_details=authorization_details,
)

args, kwargs = mock_requests_request.call_args
sent = parse_qs(kwargs["data"])

self.assertEqual(json.loads(sent["authorization_details"][0]), authorization_details)

@mock.patch("auth0.authentication.rest.RestClient.post")
def test_jar(self, mock_post):
a = PushedAuthorizationRequests("my.domain.com", "cid", client_secret="sh!")
Expand Down