Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Adding Support For RAR and JAR Requests
  • Loading branch information
kishore7snehil committed Jan 29, 2025
commit edbc0bca855e1231af671ccfcaa41c9467cc1e3c
2 changes: 2 additions & 0 deletions auth0/authentication/pushed_authorization_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def pushed_authorization_request(
redirect_uri (str): The URL to which Auth0 will redirect the browser after authorization has been granted
by the user.
**kwargs: Other fields to send along with the PAR.
For RAR requests, authorization_details parameter should be added in a proper format. See:https://datatracker.ietf.org/doc/html/rfc9396
For JAR requests, requests parameter should be send with the JWT as the value. See: https://datatracker.ietf.org/doc/html/rfc9126#name-the-request-request-paramet

See: https://www.rfc-editor.org/rfc/rfc9126.html
"""
Expand Down
57 changes: 57 additions & 0 deletions auth0/test/authentication/test_pushed_authorization_requests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import json
from unittest import mock

from ...authentication.pushed_authorization_requests import PushedAuthorizationRequests
Expand Down Expand Up @@ -45,3 +46,59 @@ def test_par_custom_params(self, mock_post):
"foo": "bar",
},
)

@mock.patch("auth0.rest.RestClient.post")
def test_rar(self, mock_post):
a = PushedAuthorizationRequests("my.domain.com", "cid", client_secret="sh!")
a.pushed_authorization_request(
response_type="code",
redirect_uri="https://example.com/callback",
authorization_details=[{"type": "money_transfer", "instructedAmount": {"amount": 2500, "currency": "USD"}}],
)

args, kwargs = mock_post.call_args

expected_data = {
"client_id": "cid",
"client_secret": "sh!",
"response_type": "code",
"redirect_uri": "https://example.com/callback",
"authorization_details": [{"type": "money_transfer", "instructedAmount": {"amount": 2500, "currency": "USD"}}],
}

actual_data = kwargs["data"]

self.assertEqual(args[0], "https://my.domain.com/oauth/par")

self.assertEqual(
json.dumps(actual_data, sort_keys=True),
json.dumps(expected_data, sort_keys=True)
)

@mock.patch("auth0.rest.RestClient.post")
def test_jar(self, mock_post):
a = PushedAuthorizationRequests("my.domain.com", "cid", client_secret="sh!")
a.pushed_authorization_request(
response_type="code",
redirect_uri="https://example.com/callback",
request="my-jwt-request",
)

args, kwargs = mock_post.call_args

expected_data = {
"client_id": "cid",
"client_secret": "sh!",
"response_type": "code",
"redirect_uri": "https://example.com/callback",
"request": 'my-jwt-request',
}

actual_data = kwargs["data"]

self.assertEqual(args[0], "https://my.domain.com/oauth/par")

self.assertEqual(
json.dumps(actual_data, sort_keys=True),
json.dumps(expected_data, sort_keys=True)
)