Add tests for passing code_verifier
ref:
@@ -148,6 +148,41 @@ class DjangoOAuthTest(TestCase):
token = client.authorize_access_token(request)
self.assertEqual(token['access_token'], 'a')
+ def test_oauth2_authorize_code_verifier(self):
+ request = self.factory.get('/login')
+ request.session = self.factory.session
+
+ oauth = OAuth()
+ client = oauth.register(
+ 'dev',
+ client_id='dev',
+ api_base_url='https://i.b/api',
+ access_token_url='https://i.b/token',
+ authorize_url='https://i.b/authorize',
+ client_kwargs={'code_challenge_method': 'S256'},
+ )
+ state = 'foo'
+ code_verifier = 'bar'
+ rv = client.authorize_redirect(
+ request, 'https://a.b/c',
+ state=state, code_verifier=code_verifier
+ )
+ self.assertEqual(rv.status_code, 302)
+ url = rv.get('Location')
+ self.assertIn('state=', url)
+ self.assertIn('code_challenge=', url)
+
+ with mock.patch('requests.sessions.Session.send') as send:
+ send.return_value = mock_send_value(get_bearer_token())
+
+ request = self.factory.get('/authorize?state={}'.format(state))
+ request.session = self.factory.session
+ request.session['_dev_authlib_state_'] = state
+ request.session['_dev_authlib_code_verifier_'] = code_verifier
+
+ token = client.authorize_access_token(request)
+ self.assertEqual(token['access_token'], 'a')
+
def test_openid_authorize(self):
request = self.factory.get('/login')
request.session = self.factory.session
