@@ -332,3 +332,60 @@ def test_fetch_access_token(self):
332332 authorization_response = "https://i.b/?code=hello" ,
333333 )
334334 assert token ["token_type" ] == "Bearer"
335+
336+
337+ def access_and_refresh_token_request_compliance_fix_test (session , client_secret ):
338+ def _non_compliant_header (url , headers , body ):
339+ headers ["X-Client-Secret" ] = client_secret
340+ return url , headers , body
341+
342+ session .register_compliance_hook ("access_token_request" , _non_compliant_header )
343+ session .register_compliance_hook ("refresh_token_request" , _non_compliant_header )
344+ return session
345+
346+
347+ class RefreshTokenRequestComplianceFixTest (TestCase ):
348+ value_to_test_for = "value_to_test_for"
349+
350+ def setUp (self ):
351+ mocker = requests_mock .Mocker ()
352+ mocker .post (
353+ "https://example.com/token" ,
354+ request_headers = {"X-Client-Secret" : self .value_to_test_for },
355+ json = {
356+ "access_token" : "this is the access token" ,
357+ "expires_in" : 7200 ,
358+ "token_type" : "Bearer" ,
359+ },
360+ headers = {"Content-Type" : "application/json" },
361+ )
362+ mocker .post (
363+ "https://example.com/refresh" ,
364+ request_headers = {"X-Client-Secret" : self .value_to_test_for },
365+ json = {
366+ "access_token" : "this is the access token" ,
367+ "expires_in" : 7200 ,
368+ "token_type" : "Bearer" ,
369+ },
370+ headers = {"Content-Type" : "application/json" },
371+ )
372+ mocker .start ()
373+ self .addCleanup (mocker .stop )
374+
375+ session = OAuth2Session ()
376+ self .fixed_session = access_and_refresh_token_request_compliance_fix_test (
377+ session , self .value_to_test_for
378+ )
379+
380+ def test_access_token (self ):
381+ token = self .fixed_session .fetch_token (
382+ "https://example.com/token" ,
383+ authorization_response = "https://i.b/?code=hello" ,
384+ )
385+ assert token ["token_type" ] == "Bearer"
386+
387+ def test_refresh_token (self ):
388+ token = self .fixed_session .refresh_token (
389+ "https://example.com/refresh" ,
390+ )
391+ assert token ["token_type" ] == "Bearer"
0 commit comments