Skip to content

Commit 747eacb

Browse files
committed
DOMO-352334: Slight refactoring and resizing lines
1 parent 3af5586 commit 747eacb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

pydomo/Transport.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,12 @@ def _renew_access_token(self):
9696
def _extract_expiration(self, access_token):
9797
expiration_date = 0
9898
try:
99-
token_parts = access_token.split('.')
100-
payload_bytes = bytes(token_parts[1], 'utf-8')
101-
102-
# Padding required for the base64 library
103-
decoded_payload_bytes = base64.urlsafe_b64decode(payload_bytes + b'==')
104-
payload_string = decoded_payload_bytes.decode('utf-8')
105-
decoded_payload_dict = json.loads(payload_string)
99+
decoded_payload_dict = self._decode_payload(access_token)
106100

107101
if 'exp' in decoded_payload_dict.keys():
108102
expiration_date = decoded_payload_dict['exp']
109-
self.logger.debug('Token expiration: {}'.format(expiration_date))
103+
self.logger.debug('Token expiration: {}'
104+
.format(expiration_date))
110105
except Exception as err:
111106
# If an Exception is raised, log and continue. expiration_date will
112107
# either be 0 or set to the value in the JWT.
@@ -115,6 +110,15 @@ def _extract_expiration(self, access_token):
115110
'{}: {}'.format(type(err).__name__, err))
116111
return expiration_date
117112

113+
def _decode_payload(self, access_token):
114+
token_parts = access_token.split('.')
115+
116+
# Padding required for the base64 library
117+
payload_bytes = bytes(token_parts[1], 'utf-8') + b'=='
118+
decoded_payload_bytes = base64.urlsafe_b64decode(payload_bytes)
119+
payload_string = decoded_payload_bytes.decode('utf-8')
120+
return json.loads(payload_string)
121+
118122
def dump_response(self, response):
119123
data = dump.dump_all(response)
120124
return str(data.decode('utf-8'))

0 commit comments

Comments
 (0)