Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41329e6

Browse files
authored
[SDK-4138] Add support for Pushed Authorization Requests (PAR) (auth0#560)
2 parents 27e2fd3 + 1b7ed4c commit 41329e6

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from typing import Any
2+
3+
from .base import AuthenticationBase
4+
5+
6+
class PushedAuthorizationRequests(AuthenticationBase):
7+
"""Pushed Authorization Request (PAR) endpoint"""
8+
9+
def pushed_authorization_request(
10+
self, response_type: str, redirect_uri: str, **kwargs
11+
) -> Any:
12+
"""Send a Pushed Authorization Request (PAR).
13+
14+
Args:
15+
response_type (str): Indicates to Auth0 which OAuth 2.0 flow you want to perform.
16+
redirect_uri (str): The URL to which Auth0 will redirect the browser after authorization has been granted
17+
by the user.
18+
**kwargs: Other fields to send along with the PAR.
19+
20+
See: https://www.rfc-editor.org/rfc/rfc9126.html
21+
"""
22+
return self.authenticated_post(
23+
f"{self.protocol}://{self.domain}/oauth/par",
24+
data={
25+
"client_id": self.client_id,
26+
"response_type": response_type,
27+
"redirect_uri": redirect_uri,
28+
**kwargs,
29+
},
30+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import unittest
2+
from unittest import mock
3+
4+
from ...authentication.pushed_authorization_requests import PushedAuthorizationRequests
5+
6+
7+
class TestRevokeToken(unittest.TestCase):
8+
@mock.patch("auth0.rest.RestClient.post")
9+
def test_par(self, mock_post):
10+
a = PushedAuthorizationRequests("my.domain.com", "cid", client_secret="sh!")
11+
a.pushed_authorization_request(
12+
response_type="code", redirect_uri="https://example.com/callback"
13+
)
14+
15+
args, kwargs = mock_post.call_args
16+
17+
self.assertEqual(args[0], "https://my.domain.com/oauth/par")
18+
self.assertEqual(
19+
kwargs["data"],
20+
{
21+
"client_id": "cid",
22+
"client_secret": "sh!",
23+
"response_type": "code",
24+
"redirect_uri": "https://example.com/callback",
25+
},
26+
)
27+
28+
@mock.patch("auth0.rest.RestClient.post")
29+
def test_par_custom_params(self, mock_post):
30+
a = PushedAuthorizationRequests("my.domain.com", "cid", client_secret="sh!")
31+
a.pushed_authorization_request(
32+
response_type="code", redirect_uri="https://example.com/callback", foo="bar"
33+
)
34+
35+
args, kwargs = mock_post.call_args
36+
37+
self.assertEqual(args[0], "https://my.domain.com/oauth/par")
38+
self.assertEqual(
39+
kwargs["data"],
40+
{
41+
"client_id": "cid",
42+
"client_secret": "sh!",
43+
"response_type": "code",
44+
"redirect_uri": "https://example.com/callback",
45+
"foo": "bar",
46+
},
47+
)

0 commit comments

Comments
 (0)