Skip to content

Commit 7181816

Browse files
committed
Updates for CIBA with email
1 parent 49da078 commit 7181816

File tree

4 files changed

+84
-13
lines changed

4 files changed

+84
-13
lines changed

auth0/authentication/back_channel_login.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def back_channel_login(
1414
login_hint: str,
1515
scope: str,
1616
authorization_details: Optional[Union[str, List[Dict]]] = None,
17+
requested_expiry: Optional[int] = None,
1718
**kwargs
1819
) -> Any:
1920
"""Send a Back-Channel Login.
@@ -31,6 +32,9 @@ def back_channel_login(
3132
authorization_details (str, list of dict, optional): JSON string or a list of dictionaries representing
3233
Rich Authorization Requests (RAR) details to include in the CIBA request.
3334
35+
requested_expiry (int, optional): Number of seconds the authentication request is valid for.
36+
Auth0 defaults to 30 seconds if not provided.
37+
3438
**kwargs: Other fields to send along with the request.
3539
3640
Returns:
@@ -50,7 +54,10 @@ def back_channel_login(
5054
data["authorization_details"] = authorization_details
5155
elif isinstance(authorization_details, list):
5256
data["authorization_details"] = json.dumps(authorization_details)
53-
57+
58+
if requested_expiry is not None:
59+
data["requested_expiry"] = str(requested_expiry)
60+
5461
data.update(kwargs)
5562

5663
return self.authenticated_post(

auth0/authentication/get_token.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def backchannel_login(
266266
use urn:openid:params:grant-type:ciba
267267
268268
Returns:
269-
access_token, id_token
269+
access_token, id_token, refresh_token, token_type, expires_in, scope and authorization_details
270270
"""
271271

272272
return self.authenticated_post(
@@ -284,7 +284,8 @@ def access_token_for_connection(
284284
subject_token: str,
285285
requested_token_type: str,
286286
connection: str | None = None,
287-
grant_type: str = "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token"
287+
grant_type: str = "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token",
288+
login_hint: str = None
288289
) -> Any:
289290
"""Calls /oauth/token endpoint with federated-connection-access-token grant type
290291
@@ -293,22 +294,29 @@ def access_token_for_connection(
293294
294295
subject_token (str): String containing the value of subject_token_type.
295296
296-
requested_token_type (str): String containing the type of rquested token.
297+
requested_token_type (str): String containing the type of requested token.
297298
298299
connection (str, optional): Denotes the name of a social identity provider configured to your application
299300
301+
login_hint (str, optional): A hint to the OpenID Provider regarding the end-user for whom authentication is being requested
302+
300303
Returns:
301-
access_token, scope, issued_token_type, token_type
304+
access_token, scope, issued_token_type, token_type, expires_in
302305
"""
303306

307+
data = {
308+
"client_id": self.client_id,
309+
"grant_type": grant_type,
310+
"subject_token_type": subject_token_type,
311+
"subject_token": subject_token,
312+
"requested_token_type": requested_token_type,
313+
"connection": connection,
314+
}
315+
316+
if login_hint:
317+
data["login_hint"] = login_hint
318+
304319
return self.authenticated_post(
305320
f"{self.protocol}://{self.domain}/oauth/token",
306-
data={
307-
"client_id": self.client_id,
308-
"grant_type": grant_type,
309-
"subject_token_type": subject_token_type,
310-
"subject_token": subject_token,
311-
"requested_token_type": requested_token_type,
312-
"connection": connection,
313-
},
321+
data=data,
314322
)

auth0/test/authentication/test_back_channel_login.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,28 @@ def test_with_authorization_details(self, mock_post):
136136
"Request data does not match expected data after JSON serialization."
137137
)
138138

139+
@mock.patch("auth0.rest.RestClient.post")
140+
def test_with_request_expiry(self, mock_post):
141+
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec")
142+
143+
g.back_channel_login(
144+
binding_message="This is a binding message",
145+
login_hint="{ \"format\": \"iss_sub\", \"iss\": \"https://my.domain.auth0.com/\", \"sub\": \"auth0|[USER ID]\" }",
146+
scope="openid",
147+
requested_expiry=100
148+
)
149+
150+
args, kwargs = mock_post.call_args
151+
152+
self.assertEqual(args[0], "https://my.domain.com/bc-authorize")
153+
self.assertEqual(
154+
kwargs["data"],
155+
{
156+
"client_id": "cid",
157+
"client_secret": "clsec",
158+
"binding_message": "This is a binding message",
159+
"login_hint": "{ \"format\": \"iss_sub\", \"iss\": \"https://my.domain.auth0.com/\", \"sub\": \"auth0|[USER ID]\" }",
160+
"scope": "openid",
161+
"requested_expiry": "100",
162+
},
163+
)

auth0/test/authentication/test_get_token.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,35 @@ def test_connection_login(self, mock_post):
364364
"requested_token_type": "http://auth0.com/oauth/token-type/federated-connection-access-token",
365365
"connection": "google-oauth2"
366366
},
367+
)
368+
369+
@mock.patch("auth0.rest.RestClient.post")
370+
def test_connection_loginwith_login_hint(self, mock_post):
371+
g = GetToken("my.domain.com", "cid", client_secret="csec")
372+
373+
g.access_token_for_connection(
374+
subject_token_type="urn:ietf:params:oauth:token-type:refresh_token",
375+
subject_token="refid",
376+
requested_token_type="http://auth0.com/oauth/token-type/federated-connection-access-token",
377+
connection="google-oauth2",
378+
login_hint="[email protected]"
379+
)
380+
381+
args, kwargs = mock_post.call_args
382+
383+
print(kwargs["data"])
384+
385+
self.assertEqual(args[0], "https://my.domain.com/oauth/token")
386+
self.assertEqual(
387+
kwargs["data"],
388+
{
389+
"grant_type": "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token",
390+
"client_id": "cid",
391+
"client_secret": "csec",
392+
"subject_token_type": "urn:ietf:params:oauth:token-type:refresh_token",
393+
"subject_token": "refid",
394+
"requested_token_type": "http://auth0.com/oauth/token-type/federated-connection-access-token",
395+
"connection": "google-oauth2",
396+
"login_hint": "[email protected]"
397+
},
367398
)

0 commit comments

Comments
 (0)