Skip to content

Commit ba032e8

Browse files
fix: handle authorization_details in back_channel_login (#695)
### Changes - Add support for `authorization_details `parameter in back_channel_login method - Serialize `authorization_details` to JSON strings before sending requests - Update docstrings to clarify expected formats for `authorization_details` - Modify tests to expect serialized JSON strings for `authorization_details` ### References - [Back-Channel Login](https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-initiated-backchannel-authentication-flow/user-authentication-with-ciba) - [Back Channel Login Auth API](https://auth0.com/docs/api/authentication/login/start-back-channel-login) ### Testing - [x] This change adds test coverage - [x] This change has been tested on the latest version of the platform/language or why not ### Contributor Checklist - [x] I agree to adhere to the [Auth0 General Contribution Guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md). - [x] I agree to uphold the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).
1 parent a3619c5 commit ba032e8

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
3939
strategy:
4040
matrix:
41-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
41+
python-version: ["3.9", "3.10", "3.11", "3.12"]
4242

4343
steps:
4444
- name: Checkout code
@@ -82,4 +82,4 @@ jobs:
8282
name: Upload coverage
8383
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # pin@5.4.2
8484
with:
85-
token: ${{ secrets.CODECOV_TOKEN }}
85+
token: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,60 @@
1-
from typing import Any
1+
from typing import Any, Optional, Union, List, Dict
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): JSON string containing user details for authentication in the iss_sub format.Ensure
26+
serialization before passing.
1927
2028
scope(str): "openid" is a required scope.Multiple scopes are separated
2129
with whitespace.
2230
23-
**kwargs: Other fields to send along with the PAR.
31+
authorization_details (str, list of dict, optional): JSON string or a list of dictionaries representing
32+
Rich Authorization Requests (RAR) details to include in the CIBA request.
33+
34+
**kwargs: Other fields to send along with the request.
2435
2536
Returns:
2637
auth_req_id, expires_in, interval
2738
"""
28-
return self.authenticated_post(
29-
f"{self.protocol}://{self.domain}/bc-authorize",
30-
data={
39+
40+
data = {
3141
"client_id": self.client_id,
3242
"binding_message": binding_message,
3343
"login_hint": login_hint,
3444
"scope": scope,
3545
**kwargs,
36-
},
46+
}
47+
48+
if authorization_details is not None:
49+
if isinstance(authorization_details, str):
50+
data["authorization_details"] = authorization_details
51+
elif isinstance(authorization_details, list):
52+
data["authorization_details"] = json.dumps(authorization_details)
53+
54+
data.update(kwargs)
55+
56+
return self.authenticated_post(
57+
f"{self.protocol}://{self.domain}/bc-authorize",
58+
data = data,
3759
headers={"Content-Type": "application/x-www-form-urlencoded"},
3860
)

auth0/test/authentication/test_back_channel_login.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_with_authorization_details(self, mock_post):
8080
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec")
8181
g.back_channel_login(
8282
binding_message="This is a binding message.",
83-
login_hint={"format": "iss_sub", "iss": "https://my.domain.auth0.com/", "sub": "auth0|USER_ID"},
83+
login_hint= json.dumps({"format": "iss_sub", "iss": "https://my.domain.auth0.com/", "sub": "auth0|USER_ID"}),
8484
scope="openid",
8585
authorization_details=[
8686
{
@@ -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": json.dumps({"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)