login finally works

This commit is contained in:
Carlos Sanchez 2023-04-30 22:13:01 -04:00
parent 818333de54
commit 60cb4f816e
2 changed files with 5 additions and 7 deletions

View File

@ -34,7 +34,7 @@ class ApiContext:
"Accept" : content_type "Accept" : content_type
} }
if self.token: if self.token:
headers["Authorization"] = "Bearer" + self.token headers["Authorization"] = "Bearer " + self.token
return headers return headers
# Given a standard response from the API, parse the status code to throw the appropriate # 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, # 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 # check if only the given token is valid
def is_token_valid(self, token = False): def is_token_valid(self):
if not token:
token = self.token
try: try:
return token and self.get("user/me") return self.token and self.get("user/me")
except Exception as ex: except Exception as ex:
self.logger.debug("Error from endpoint: %s" % ex) self.logger.debug("Error from endpoint: %s" % ex)
return False return False

View File

@ -57,8 +57,8 @@ def authenticate(config, context: contentapi.ApiContext):
with open(config["tokenfile"], 'r') as f: with open(config["tokenfile"], 'r') as f:
token = f.read() token = f.read()
logging.debug("Token from file: " + token) 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"]) logging.info("Logged in using token file " + config["tokenfile"])
return return
else: else: