-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjwt_lint.py
More file actions
31 lines (27 loc) · 972 Bytes
/
Copy pathjwt_lint.py
File metadata and controls
31 lines (27 loc) · 972 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
#!/usr/bin/env python3
import argparse, base64, json, time
def b64url(data):
data += '=' * (-len(data)%4)
return base64.urlsafe_b64decode(data.encode())
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--token", required=True)
args = ap.parse_args()
try:
header_b64, payload_b64, _sig = args.token.split(".")
header = json.loads(b64url(header_b64))
payload = json.loads(b64url(payload_b64))
print("== Header ==")
print(json.dumps(header, indent=2))
print("== Payload ==")
print(json.dumps(payload, indent=2))
now = int(time.time())
for claim in ["exp","iat","nbf"]:
if claim in payload:
print(f"[check] {claim} = {payload[claim]} (now={now})")
alg = header.get("alg","none")
print(f"[info] alg={alg}")
except Exception as e:
print("Invalid token or parse error:", e)
if __name__ == "__main__":
main()