Last active
October 7, 2025 18:30
-
-
Save kgantsov/40f6de52af9eb84d95f639da75855763 to your computer and use it in GitHub Desktop.
Script for printing JWT token's payload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import argparse | |
| import base64 | |
| import json | |
| import typing | |
| from datetime import datetime | |
| def parse_jwt_token(token_part: str) -> dict[str, typing.Any]: | |
| token_part_with_padding = f"{token_part}{'=' * (len(token_part) % 4)}" | |
| return json.loads(base64.b64decode(token_part_with_padding)) | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('token', help='JWT token to parse') | |
| args = parser.parse_args() | |
| header, payload, _ = args.token.split(".") | |
| header_data = parse_jwt_token(header) | |
| token_data = parse_jwt_token(payload) | |
| print(f"Token Header: {header_data}") | |
| print(f"Token Data: {token_data}") | |
| if 'exp' in token_data: | |
| print(f"Expiration Time: {datetime.fromtimestamp(token_data['exp'])}") | |
| else: | |
| print("Expiration Time: Not available") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment