# Path: atlassian_jwt_auth/exceptions.py
# class PublicKeyRetrieverException(_WithStatus, ASAPAuthenticationException):
#     """Raise when there are issues retrieving the public key"""
# 
# class NoTokenProvidedError(ASAPAuthenticationException):
#     """Raise when no token is provided"""
#     pass
# 
# class JtiUniquenessException(ASAPAuthenticationException):
#     """Raise when a JTI is seen more than once. """
# 
# class SubjectDoesNotMatchIssuerException(ASAPAuthenticationException):
#     """Raise when the subject and issuer differ. """


import logging
from jwt.exceptions import InvalidIssuerError, InvalidTokenError
from atlassian_jwt_auth.exceptions import (
    PublicKeyRetrieverException,
    NoTokenProvidedError,
    JtiUniquenessException,
    SubjectDoesNotMatchIssuerException,
)




def _process_asap_token(request, backend, settings, verifier=None):
    """ Verifies an ASAP token, validates the claims, and returns an error
    response"""
    logger = logging.getLogger('asap')
    token = backend.get_asap_token(request)
    error_response = None
    if token is None and not settings.ASAP_REQUIRED and (
            settings.ASAP_REQUIRED is not None):
        return
    try:
        if token is None:
            raise NoTokenProvidedError
        if verifier is None:
            verifier = backend.get_verifier(settings=settings)
        asap_claims = verifier.verify_jwt(
            token,
            settings.ASAP_VALID_AUDIENCE,
            leeway=settings.ASAP_VALID_LEEWAY,
        )

        _verify_issuers(asap_claims, settings.ASAP_VALID_ISSUERS)
        backend.set_asap_claims_for_request(request, asap_claims)

# Path: atlassian_jwt_auth/exceptions.py
# class PublicKeyRetrieverException(_WithStatus, ASAPAuthenticationException):
#     """Raise when there are issues retrieving the public key"""
# 
# class NoTokenProvidedError(ASAPAuthenticationException):
#     """Raise when no token is provided"""
#     pass
# 
# class JtiUniquenessException(ASAPAuthenticationException):
#     """Raise when a JTI is seen more than once. """
# 
# class SubjectDoesNotMatchIssuerException(ASAPAuthenticationException):
#     """Raise when the subject and issuer differ. """


# Path: atlassian_jwt_auth/frameworks/common/asap.py
import logging
from jwt.exceptions import InvalidIssuerError, InvalidTokenError
from atlassian_jwt_auth.exceptions import (
    PublicKeyRetrieverException,
    NoTokenProvidedError,
    JtiUniquenessException,
    SubjectDoesNotMatchIssuerException,
)





def _process_asap_token(request, backend, settings, verifier=None):
    """ Verifies an ASAP token, validates the claims, and returns an error
    response"""
    logger = logging.getLogger('asap')
    token = backend.get_asap_token(request)
    error_response = None
    if token is None and not settings.ASAP_REQUIRED and (
            settings.ASAP_REQUIRED is not None):
        return
    try:
        if token is None:
            raise NoTokenProvidedError
        if verifier is None:
            verifier = backend.get_verifier(settings=settings)
        asap_claims = verifier.verify_jwt(
            token,
            settings.ASAP_VALID_AUDIENCE,
            leeway=settings.ASAP_VALID_LEEWAY,
        )

        _verify_issuers(asap_claims, settings.ASAP_VALID_ISSUERS)
        backend.set_asap_claims_for_request(request, asap_claims)

    except NoTokenProvidedError: