@@ -332,3 +332,58 @@ def test_fetch_access_token(self):
332
332
authorization_response = "https://i.b/?code=hello" ,
333
333
)
334
334
assert token ["token_type" ] == "Bearer"
335
+
336
+
337
+ def access_and_refresh_token_request_compliance_fix_test (session , client_secret : str ):
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 (session , self .value_to_test_for )
377
+
378
+ def test_access_token (self ):
379
+ token = self .fixed_session .fetch_token (
380
+ "https://example.com/token" ,
381
+ authorization_response = "https://i.b/?code=hello" ,
382
+ )
383
+ assert token ["token_type" ] == "Bearer"
384
+
385
+ def test_refresh_token (self ):
386
+ token = self .fixed_session .refresh_token (
387
+ "https://example.com/refresh" ,
388
+ )
389
+ assert token ["token_type" ] == "Bearer"
0 commit comments