def validate_token(self, token):
    secret = self.config.get('jwt').get('secret')
    algorithm = self.config.get('jwt').get('algorithm')
    expire_minutes = self.config.get('jwt').get('expires')
    authenticates = self.config.get('jwt').get('authenticates')
    version = self.config.get('jwt').get('version')
    if expire_minutes:
        expire_minutes = pendulum.now(tz='UTC').add(minutes=expire_minutes).to_datetime_string()
    try:
        unencrypted_token = jwt.decode(token, secret, algorithms=[algorithm])
    except (jwt.InvalidSignatureError, jwt.DecodeError):
        return False
    expires = unencrypted_token.get('expires')
    if version:
        if (unencrypted_token['version'] != version):
            return False
    if authenticates:
        return self.attempt_by_token(token)
    if (not expires):
        return True
    expired = pendulum.parse(expires, tz='UTC').is_past()
    if expired:
        return False
    return True
def validate_token(self, token):
    secret = self.config.get('jwt').get('secret')
    algorithm = self.config.get('jwt').get('algorithm')
    expire_minutes = self.config.get('jwt').get('expires')
    authenticates = self.config.get('jwt').get('authenticates')
    version = self.config.get('jwt').get('version')
    if expire_minutes:
        expire_minutes = pendulum.now(tz='UTC').add(minutes=expire_minutes).to_datetime_string()
    try:
        unencrypted_token = jwt.decode(token, secret, algorithms=[algorithm])
    except (jwt.InvalidSignatureError, jwt.DecodeError):
        return False
    expires = unencrypted_token.get('expires')
    if version:
        if (unencrypted_token['version'] != version):
            return False
    if authenticates:
        return self.attempt_by_token(token)
    if (not expires):
        return True
    expired = pendulum.parse(expires, tz='UTC').is_past()
    if expired:
        return False
    return True