def check_token_status(self):
"""
Simple request to check if session has expired (TBD)
:return: Token status
"""
if self.access_token is None:
try:
token_file = self.platform['credentials']['token_file']
token_path = os.path.join(
self.workspace.workspace_root,
self.workspace.platforms_dir,
token_file)
# Construct the POST login request
with open(token_path, "r") as _file:
self.access_token = _file.read
except:
return True
print('Public_key=', self.platform_public_key)
if self.platform_public_key is None:
return True
# Some old PyJWT versions crash with public key binary string, instead add
# self.platform_public_key.decode('utf-8')
try:
print('access_token=', self.access_token)
print('platform_public_key=', self.platform_public_key.decode('utf-8'))
decoded = jwt.decode(self.access_token, self.platform_public_key.decode('utf-8'),
True, algorithms='RS256', audience='adapter')
# options={'verify_aud': False})
print('contents', decoded)
try:
self.username = decoded['preferred_username']
return True
except:
return True
except jwt.DecodeError:
print('Token cannot be decoded because it failed validation')
return False
except jwt.ExpiredSignatureError:
print('Signature has expired')
return False
except jwt.InvalidIssuerError:
return False
except jwt.InvalidIssuedAtError:
return False
评论列表
文章目录