-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJWT_read
More file actions
executable file
·38 lines (31 loc) · 882 Bytes
/
JWT_read
File metadata and controls
executable file
·38 lines (31 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env -S uv run --script
# vi: ft=python
# /// script
# requires-python = ">=3.7"
# dependencies = [
# "PyJWT",
# ]
# ///
import jwt
import json
import sys
def main():
# Read the token from stdin
token = sys.stdin.read().strip()
if not token:
print(f"Usage: echo <token> | {sys.argv[0]}")
exit(1)
try:
# If token is surrounded by quotes, remove them (e.g. when token comes from jq)
if token.startswith('"') and token.endswith('"'):
token = token[1:-1]
# Decode the token without verifying the signature
decoded = jwt.decode(
token, options={"verify_signature": False}
) # works in PyJWT >= v2.0
print(json.dumps(decoded, indent=4))
except Exception as e:
print(f"Error decoding token: {e}")
exit(1)
if __name__ == "__main__":
main()