Skip to content

Commit b95cb5a

Browse files
fix: support authorization_details
1 parent a3619c5 commit b95cb5a

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,59 @@
1-
from typing import Any
1+
from typing import Any, Optional, Union
22

33
from .base import AuthenticationBase
44

5+
import json
6+
57

68
class BackChannelLogin(AuthenticationBase):
79
"""Back-Channel Login endpoint"""
810

911
def back_channel_login(
10-
self, binding_message: str, login_hint: str, scope: str, **kwargs
12+
self,
13+
binding_message: str,
14+
login_hint: str,
15+
scope: str,
16+
authorization_details: Optional[Union[str, list[dict]]] = None,
17+
**kwargs
1118
) -> Any:
1219
"""Send a Back-Channel Login.
1320
1421
Args:
1522
binding_message (str): Human-readable string displayed on both the device calling /bc-authorize and the user’s
1623
authentication device to ensure the user is approves the correct request.
1724
18-
login_hint (str): String containing information about the user to contact for authentication.
25+
login_hint (str): A JSON object containing user details for authentication in the iss_sub format.
1926
2027
scope(str): "openid" is a required scope.Multiple scopes are separated
2128
with whitespace.
2229
23-
**kwargs: Other fields to send along with the PAR.
30+
authorization_details (str, list of dict, or dict, optional): JSON string or dictionary representing
31+
Rich Authorization Requests (RAR) details to include in the CIBA request.
32+
33+
**kwargs: Other fields to send along with the request.
2434
2535
Returns:
2636
auth_req_id, expires_in, interval
2737
"""
28-
return self.authenticated_post(
29-
f"{self.protocol}://{self.domain}/bc-authorize",
30-
data={
38+
39+
data = {
3140
"client_id": self.client_id,
3241
"binding_message": binding_message,
3342
"login_hint": login_hint,
3443
"scope": scope,
3544
**kwargs,
36-
},
45+
}
46+
47+
if authorization_details is not None:
48+
if isinstance(authorization_details, str):
49+
data["authorization_details"] = authorization_details
50+
elif isinstance(authorization_details, (list, dict)):
51+
data["authorization_details"] = json.dumps(authorization_details)
52+
53+
data.update(kwargs)
54+
55+
return self.authenticated_post(
56+
f"{self.protocol}://{self.domain}/bc-authorize",
57+
data = data,
3758
headers={"Content-Type": "application/x-www-form-urlencoded"},
3859
)

auth0/test/authentication/test_back_channel_login.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ def test_with_authorization_details(self, mock_post):
106106
"client_id": "cid",
107107
"client_secret": "clsec",
108108
"binding_message": "This is a binding message.",
109-
"login_hint": {"format": "iss_sub", "iss": "https://my.domain.auth0.com/", "sub": "auth0|USER_ID" },
109+
"login_hint": {"format": "iss_sub", "iss": "https://my.domain.auth0.com/", "sub": "auth0|USER_ID"},
110110
"scope": "openid",
111-
"authorization_details": [
111+
"authorization_details": json.dumps([
112112
{
113113
"type":"payment_initiation","locations":["https://example.com/payments"],
114114
"instructedAmount":
@@ -122,17 +122,17 @@ def test_with_authorization_details(self, mock_post):
122122
"iban":"DE021001001093071118603"
123123
},
124124
"remittanceInformationUnstructured":"Ref Number Merchant"
125-
}],
125+
}
126+
]),
126127
}
127128

128129
actual_data = kwargs["data"]
129-
130+
130131
self.assertEqual(args[0], "https://my.domain.com/bc-authorize")
131-
132+
132133
self.assertEqual(
133-
json.dumps(actual_data, sort_keys=True),
134-
json.dumps(expected_data, sort_keys=True)
134+
actual_data,
135+
expected_data,
136+
"Request data does not match expected data after JSON serialization."
135137
)
136138

137-
138-

0 commit comments

Comments
 (0)