Skip to content

Commit

Permalink
Adds forward compatibility with PyJWT==2
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrJander committed Jan 12, 2021
1 parent a97f63d commit fed4492
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions neptune/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from neptune.utils import with_api_exceptions_handler, update_session_proxies


_decoding_options = {"verify_signature": False, 'verify_aud': False}


class NeptuneAuth(AuthBase):
__LOCK = threading.RLock()

Expand Down Expand Up @@ -66,7 +69,7 @@ def _refresh_token(self):
def _refresh_session_token(self):
self.session.refresh_token(self.session.auto_refresh_url, verify=self.session.verify)
if self.session.token is not None and self.session.token.get('access_token') is not None:
decoded_json_token = jwt.decode(self.session.token.get('access_token'), verify=False)
decoded_json_token = jwt.decode(self.session.token.get('access_token'), options=_decoding_options)
self.token_expires_at = decoded_json_token.get(u'exp')


Expand All @@ -78,7 +81,7 @@ def __init__(self, api_token, backend_client, ssl_verify, proxies):
# We need to pass a lambda to be able to re-create fresh session at any time when needed
def session_factory():
auth_tokens = backend_client.api.exchangeApiToken(X_Neptune_Api_Token=api_token).response().result
decoded_json_token = jwt.decode(auth_tokens.accessToken, verify=False)
decoded_json_token = jwt.decode(auth_tokens.accessToken, options=_decoding_options)
expires_at = decoded_json_token.get(u'exp')
client_name = decoded_json_token.get(u'azp')
refresh_url = u'{realm_url}/protocol/openid-connect/token'.format(realm_url=decoded_json_token.get(u'iss'))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ py3nvml
oauthlib>=2.1.0
pandas
Pillow>=1.1.6
PyJWT<2.0.0
PyJWT
requests>=2.20.0
requests-oauthlib>=1.0.0
six>=1.12.0
Expand Down
4 changes: 2 additions & 2 deletions tests/neptune/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from mock import MagicMock, patch
from oauthlib.oauth2 import TokenExpiredError

from neptune.oauth import NeptuneAuth, NeptuneAuthenticator, _no_token_updater
from neptune.oauth import NeptuneAuth, NeptuneAuthenticator, _no_token_updater, _decoding_options
from tests.neptune.http_objects_factory import a_request
from tests.neptune.oauth_objects_factory import SECRET, a_refresh_token, an_access_token

Expand Down Expand Up @@ -93,7 +93,7 @@ def test_apply_oauth2_session_to_request(self, time_mock, session_mock):
auth_tokens = MagicMock()
auth_tokens.accessToken = an_access_token()
auth_tokens.refreshToken = a_refresh_token()
decoded_access_token = jwt.decode(auth_tokens.accessToken, SECRET, options={'verify_exp': False})
decoded_access_token = jwt.decode(auth_tokens.accessToken, SECRET, options=_decoding_options)

backend_client.api.exchangeApiToken(X_Neptune_Api_Token=api_token).response().result = auth_tokens

Expand Down

0 comments on commit fed4492

Please sign in to comment.