From 60cb4f816e5d38d45812df376f5d0e0d120c9fce Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Sun, 30 Apr 2023 22:13:01 -0400 Subject: [PATCH] login finally works --- contentapi.py | 8 +++----- main.py | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/contentapi.py b/contentapi.py index f55bf99..5e6d5c9 100644 --- a/contentapi.py +++ b/contentapi.py @@ -34,7 +34,7 @@ class ApiContext: "Accept" : content_type } if self.token: - headers["Authorization"] = "Bearer" + self.token + headers["Authorization"] = "Bearer " + self.token return headers # Given a standard response from the API, parse the status code to throw the appropriate @@ -67,11 +67,9 @@ class ApiContext: # Connect to the API to determine if your token is still valid. Or, if you pass a token, # check if only the given token is valid - def is_token_valid(self, token = False): - if not token: - token = self.token + def is_token_valid(self): try: - return token and self.get("user/me") + return self.token and self.get("user/me") except Exception as ex: self.logger.debug("Error from endpoint: %s" % ex) return False diff --git a/main.py b/main.py index dea5787..00f1fb1 100644 --- a/main.py +++ b/main.py @@ -57,8 +57,8 @@ def authenticate(config, context: contentapi.ApiContext): with open(config["tokenfile"], 'r') as f: token = f.read() logging.debug("Token from file: " + token) - if context.is_token_valid(token): - context.token = token + context.token = token + if context.is_token_valid(): logging.info("Logged in using token file " + config["tokenfile"]) return else: