def decode_auth_token(auth_token): """ Decodes the auth token :param auth_token: :return: integer|string """ try: payload = jwt.decode(auth_token, Config.get_config()["SECRET_KEY"]) return True, payload['sub'] except jwt.ExpiredSignatureError: logging.info("SIGNATURE EXPIRED") return False, 'Signature expired. Please log in again.' except jwt.InvalidTokenError: logging.info("INVALID TOKEN") return False, 'Invalid token. Please log in again.'
def encode_auth_token(self): """ Generates the Auth Token :return: string """ try: payload = { 'exp': datetime.utcnow() + timedelta(days=30, seconds=0), 'iat': datetime.utcnow(), 'sub': self.id } return jwt.encode( payload, Config.get_config()["SECRET_KEY"], algorithm='HS256' ) except Exception as e: return e