Skip to content

Commit

Permalink
Add __str__ and __repr_ for JWT
Browse files Browse the repository at this point in the history
Signed-off-by: Simo Sorce <simo@redhat.com>
  • Loading branch information
simo5 committed May 11, 2022
1 parent 32bd68f commit 78104fc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions jwcrypto/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,18 @@ def from_jose_token(cls, token):
obj = cls()
obj.deserialize(token)
return obj

def __str__(self):
try:
return self.serialize()
except Exception: # pylint: disable=broad-except
return self.__repr__()

def __repr__(self):
jwt = repr(self.token)
return f'JWT(header={self._header}, ' + \
f'claims={self._claims}, ' + \
f'jwt={jwt}, ' + \
f'key=None, algs={self._algs}, ' + \
f'default_claims={self._reg_claims}, ' + \
f'check_claims={self._check_claims})'

0 comments on commit 78104fc

Please sign in to comment.