Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __createAuthorization__(self):
if self.session_token is not None:
# Try to load a cached social token
try:
social_token_store = Store("app://tokens/social/{username}".format(username=self.username))
social_tokens = social_token_store.retrieve()
if len(social_tokens):
for cached_token in social_tokens:
cached_token_expiration_time = datetime.fromtimestamp(jwt.decode(cached_token, verify=False)['exp'])
token_validity_time_remaining = cached_token_expiration_time - datetime.now()
if token_validity_time_remaining.total_seconds() <= 60 * 60 * 24:
self.__requestSocialToken()
else:
self.session.headers["Authorization"] = "JWT " + cached_token
else:
self.__requestSocialToken()
except:
self.__requestSocialToken()
def __createSession__(self):
# Try to load a cached token
try:
session_token_store = Store("app://tokens/session/{username}".format(username=self.username))
session_tokens = session_token_store.retrieve()
self.session_token = None
if len(session_tokens):
for cached_token in session_tokens:
cached_token_expiration_time = datetime.fromtimestamp(jwt.decode(cached_token, verify=False)['exp'])
token_validity_time_remaining = cached_token_expiration_time - datetime.now()
if token_validity_time_remaining.total_seconds() <= 60 * 60 * 24:
self.session_token = None
else:
self.session_token = cached_token
else:
self.session_token = None
except:
self.session_token = None
if self.session_token is None:
self.__requestSessionToken()
else:
pass