diff --git a/edx_rest_api_client/__version__.py b/edx_rest_api_client/__version__.py index 35424e8..4175d39 100644 --- a/edx_rest_api_client/__version__.py +++ b/edx_rest_api_client/__version__.py @@ -1 +1 @@ -__version__ = '1.9.1' +__version__ = '1.9.2' diff --git a/edx_rest_api_client/client.py b/edx_rest_api_client/client.py index c4a22d4..5de36f0 100644 --- a/edx_rest_api_client/client.py +++ b/edx_rest_api_client/client.py @@ -74,7 +74,6 @@ def get_oauth_access_token(url, client_id, client_secret, token_type='jwt', gran ) data = response.json() - try: access_token = data['access_token'] expires_in = data['expires_in'] @@ -112,14 +111,12 @@ def __init__(self, base_url, client_id, client_secret, **kwargs): def _check_auth(self): if datetime.datetime.utcnow() > self._expiration: url = self._base_url + self.oauth_uri - has_token = self.auth.token is not None - grant_type = 'refresh_token' if has_token else 'client_credentials' + grant_type = 'client_credentials' self.auth.token, self._expiration = get_oauth_access_token( url, self._client_id, self._client_secret, - grant_type=grant_type, - refresh_token=self.auth.token) + grant_type=grant_type) def request(self, method, url, **kwargs): # pylint: disable=arguments-differ """ diff --git a/edx_rest_api_client/tests/test_client.py b/edx_rest_api_client/tests/test_client.py index 1e56988..6a11d54 100644 --- a/edx_rest_api_client/tests/test_client.py +++ b/edx_rest_api_client/tests/test_client.py @@ -163,12 +163,12 @@ def test_automatic_token_refresh(self): """ Test that the JWT token is automatically refreshed """ + tokens = ['cred2', 'cred1'] + def auth_callback(request): resp = {'expires_in': 60} if 'grant_type=client_credentials' in request.body: - resp['access_token'] = 'cred' - elif 'grant_type=refresh_token' in request.body and 'refresh_token=cred' in request.body: - resp['access_token'] = 'refresh' + resp['access_token'] = tokens.pop() return (200, {}, json.dumps(resp)) responses.add_callback( @@ -180,8 +180,8 @@ def auth_callback(request): session = OAuthAPIClient(self.base_url, self.client_id, self.client_secret) self._mock_auth_api(self.base_url + '/endpoint', 200, {'status': 'ok'}) response = session.post(self.base_url + '/endpoint', data={'test': 'ok'}) - self.assertEqual(session.auth.token, 'cred') + self.assertEqual(session.auth.token, 'cred1') self.assertEqual(response.json()['status'], 'ok') with freeze_time(datetime.datetime.utcnow() + datetime.timedelta(seconds=3600)): response = session.post(self.base_url + '/endpoint', data={'test': 'ok'}) - self.assertEqual(session.auth.token, 'refresh') + self.assertEqual(session.auth.token, 'cred2')