Skip to content

Commit 3c7ad29

Browse files
committed
Sem-Ver: feature Add logging to the framework asap token checking code.
Signed-off-by: David Black <[email protected]>
1 parent 693a30f commit 3c7ad29

File tree

1 file changed

+12
-1
lines changed
  • atlassian_jwt_auth/frameworks/common

1 file changed

+12
-1
lines changed

atlassian_jwt_auth/frameworks/common/asap.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import logging
2+
13
from jwt.exceptions import InvalidIssuerError, InvalidTokenError
24

35
from atlassian_jwt_auth.exceptions import (
@@ -11,6 +13,7 @@
1113
def _process_asap_token(request, backend, settings, verifier=None):
1214
""" Verifies an ASAP token, validates the claims, and returns an error
1315
response"""
16+
logger = logging.getLogger('asap')
1417
token = backend.get_asap_token(request)
1518
error_response = None
1619
if token is None and not settings.ASAP_REQUIRED and (
@@ -30,6 +33,7 @@ def _process_asap_token(request, backend, settings, verifier=None):
3033
_verify_issuers(asap_claims, settings.ASAP_VALID_ISSUERS)
3134
backend.set_asap_claims_for_request(request, asap_claims)
3235
except NoTokenProvidedError:
36+
logger.info('No token provided')
3337
error_response = backend.get_401_response(
3438
'Unauthorized', request=request
3539
)
@@ -42,26 +46,33 @@ def _process_asap_token(request, backend, settings, verifier=None):
4246
# will return 403 for a missing file to avoid leaking
4347
# information.
4448
raise
45-
49+
logger.warning('Could not retrieve the matching public key')
4650
error_response = backend.get_401_response(
4751
'Unauthorized: Key not found', request=request
4852
)
4953
except InvalidIssuerError:
54+
logger.warning('Invalid token - issuer')
5055
error_response = backend.get_403_response(
5156
'Forbidden: Invalid token issuer', request=request
5257
)
5358
except InvalidTokenError:
59+
logger.warning('Invalid token')
5460
error_response = backend.get_401_response(
5561
'Unauthorized: Invalid token', request=request
5662
)
5763
except JtiUniquenessException:
64+
logger.warning('Invalid token - duplicate jti')
5865
error_response = backend.get_401_response(
5966
'Unauthorized: Invalid token - duplicate jti', request=request
6067
)
6168
except SubjectDoesNotMatchIssuerException:
69+
logger.warning('Invalid token - subject and issuer do not match')
6270
error_response = backend.get_401_response(
6371
'Unauthorized: Subject and Issuer do not match', request=request
6472
)
73+
except ValueError:
74+
logger.exception('An error occured while checking an asap token')
75+
raise
6576

6677
if error_response is not None and settings.ASAP_REQUIRED:
6778
return error_response

0 commit comments

Comments
 (0)