@@ -0,0 +1,1725 @@
+%22%22%22This module contains the TokenChecker class.%22%22%22%0Aimport datetime%0Aimport logging%0A%0Afrom jose import jwt%0A%0A%0Aclass TokenChecker:%0A    %22%22%22This class contains methods to check a JWT token for validity.%22%22%22%0A%0A    def __init__(self):%0A        %22%22%22Initialize a new TokenChecker.%22%22%22%0A        self.logger = logging.getLogger(__name__)%0A        # cache is used to maintain an dicitonary of issuer/cache cut off pairs%0A        self.cache = %7B%7D%0A%0A    def is_token_valid(self, token):%0A        %22%22%22Introspect a token to determine it's origin.%22%22%22%0A        jwt_unverified_json = jwt.get_unverified_claims(token)%0A%0A        if not self._is_token_json_temporally_valid(jwt_unverified_json):%0A            return False%0A%0A        return True%0A%0A    def _is_token_json_temporally_valid(self, token_json):%0A        %22%22%22%0A        Check JWT Token JSON is temporarily valid.%0A%0A        Return True if:%0A         - Both 'Issued At' (iat) and Expired' (exp) are present%0A         - iat is in the past%0A         - exp is in the future%0A        %22%22%22%0A        now = int(datetime.datetime.now().strftime('%25s'))%0A        try:%0A            # check 'iat' (issued at) is in the past and 'exp' (expires at)%0A            # is in the future%0A            if token_json%5B'iat'%5D %3E now or token_json%5B'exp'%5D %3C now:%0A                self.logger.info(%22Token 'iat' or 'exp' invalid%22)%0A                self.logger.debug(token_json)%0A                self.logger.debug(%22Time now: %25s%22, now)%0A                return False%0A        # it's possible a token doesn't have an 'iat' or 'exp'%0A        except KeyError:%0A            self.logger.info(%22Token missing 'iat' or 'exp'%22)%0A            self.logger.debug(token_json)%0A            return False%0A%0A        # if we get here, the token is temporarily valid%0A        return True%0A

Add inital TokenChecker to validate tokens