@@ -124,6 +124,27 @@ def test_authorization_url(self):
124124 self .assertIn (self .client_id , auth_url )
125125 self .assertIn ("response_type=token" , auth_url )
126126
127+ def test_pkce_authorization_url (self ):
128+ url = "https://example.com/authorize?foo=bar"
129+
130+ web = WebApplicationClient (self .client_id )
131+ s = OAuth2Session (client = web , pkce = "S256" )
132+ auth_url , state = s .authorization_url (url )
133+ self .assertIn (state , auth_url )
134+ self .assertIn (self .client_id , auth_url )
135+ self .assertIn ("response_type=code" , auth_url )
136+ self .assertIn ("code_challenge=" , auth_url )
137+ self .assertIn ("code_challenge_method=S256" , auth_url )
138+
139+ mobile = MobileApplicationClient (self .client_id )
140+ s = OAuth2Session (client = mobile , pkce = "S256" )
141+ auth_url , state = s .authorization_url (url )
142+ self .assertIn (state , auth_url )
143+ self .assertIn (self .client_id , auth_url )
144+ self .assertIn ("response_type=token" , auth_url )
145+ self .assertIn ("code_challenge=" , auth_url )
146+ self .assertIn ("code_challenge_method=S256" , auth_url )
147+
127148 @mock .patch ("time.time" , new = lambda : fake_time )
128149 def test_refresh_token_request (self ):
129150 self .expired_token = dict (self .token )
@@ -424,6 +445,16 @@ def test_web_app_fetch_token(self):
424445 authorization_response = "https://i.b/no-state?code=abc" ,
425446 )
426447
448+ @mock .patch ("time.time" , new = lambda : fake_time )
449+ def test_pkce_web_app_fetch_token (self ):
450+ url = "https://example.com/token"
451+
452+ web = WebApplicationClient (self .client_id , code = CODE )
453+ sess = OAuth2Session (client = web , token = self .token , pkce = "S256" )
454+ sess .send = fake_token (self .token )
455+ sess ._code_verifier = "foobar"
456+ self .assertEqual (sess .fetch_token (url ), self .token )
457+
427458 def test_client_id_proxy (self ):
428459 sess = OAuth2Session ("test-id" )
429460 self .assertEqual (sess .client_id , "test-id" )
0 commit comments