login finally works
This commit is contained in:
parent
818333de54
commit
60cb4f816e
@ -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
|
||||
|
4
main.py
4
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:
|
||||
|
Loading…
Reference in New Issue
Block a user