11import unittest
2+ import requests
23from fnmatch import fnmatch
34from unittest import mock
45from unittest .mock import ANY
56
67from cryptography .hazmat .primitives import asymmetric , serialization
78
9+ from ... import Auth0Error
810from ...authentication .get_token import GetToken
911
1012
@@ -335,7 +337,25 @@ def test_backchannel_login(self, mock_post):
335337 "grant_type" : "urn:openid:params:grant-type:ciba" ,
336338 },
337339 )
338-
340+
341+ @mock .patch ("requests.request" )
342+ def test_backchannel_login_headers_on_failure (self , mock_requests_request ):
343+ response = requests .Response ()
344+ response .status_code = 400
345+ response .headers = {"Retry-After" : "100" }
346+ response ._content = b'{"error":"slow_down"}'
347+ mock_requests_request .return_value = response
348+
349+ g = GetToken ("my.domain.com" , "cid" , client_secret = "csec" )
350+
351+ with self .assertRaises (Auth0Error ) as context :
352+ g .backchannel_login (
353+ auth_req_id = "reqid" ,
354+ grant_type = "urn:openid:params:grant-type:ciba" ,
355+ )
356+ self .assertEqual (context .exception .headers ["Retry-After" ], "100" )
357+ self .assertEqual (context .exception .status_code , 400 )
358+
339359 @mock .patch ("auth0.rest.RestClient.post" )
340360 def test_connection_login (self , mock_post ):
341361 g = GetToken ("my.domain.com" , "cid" , client_secret = "csec" )
@@ -364,4 +384,33 @@ def test_connection_login(self, mock_post):
364384 "requested_token_type" : "http://auth0.com/oauth/token-type/federated-connection-access-token" ,
365385 "connection" : "google-oauth2"
366386 },
387+ )
388+
389+ @mock .patch ("auth0.rest.RestClient.post" )
390+ def test_connection_login_with_login_hint (self , mock_post ):
391+ g = GetToken ("my.domain.com" , "cid" , client_secret = "csec" )
392+
393+ g .access_token_for_connection (
394+ subject_token_type = "urn:ietf:params:oauth:token-type:refresh_token" ,
395+ subject_token = "refid" ,
396+ requested_token_type = "http://auth0.com/oauth/token-type/federated-connection-access-token" ,
397+ connection = "google-oauth2" ,
398+ login_hint = "john.doe@example.com"
399+ )
400+
401+ args , kwargs = mock_post .call_args
402+
403+ self .assertEqual (args [0 ], "https://my.domain.com/oauth/token" )
404+ self .assertEqual (
405+ kwargs ["data" ],
406+ {
407+ "grant_type" : "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token" ,
408+ "client_id" : "cid" ,
409+ "client_secret" : "csec" ,
410+ "subject_token_type" : "urn:ietf:params:oauth:token-type:refresh_token" ,
411+ "subject_token" : "refid" ,
412+ "requested_token_type" : "http://auth0.com/oauth/token-type/federated-connection-access-token" ,
413+ "connection" : "google-oauth2" ,
414+ "login_hint" : "john.doe@example.com"
415+ },
367416 )
0 commit comments