Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise NeptuneInvalidApiTokenException for 401 http code #601

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion neptune/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import time

import jwt
from bravado.exception import HTTPUnauthorized
from bravado.requests_client import Authenticator
from oauthlib.oauth2 import TokenExpiredError, OAuth2Error
from requests.auth import AuthBase
from requests_oauthlib import OAuth2Session

from neptune.new.exceptions import NeptuneInvalidApiTokenException
from neptune.utils import with_api_exceptions_handler, update_session_proxies

_decoding_options = {
Expand Down Expand Up @@ -86,7 +88,11 @@ 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
try:
auth_tokens = backend_client.api.exchangeApiToken(X_Neptune_Api_Token=api_token).response().result
except HTTPUnauthorized:
raise NeptuneInvalidApiTokenException()

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')
Expand Down