summaryrefslogtreecommitdiff
path: root/jwt-decode
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-01-10 16:08:04 +0200
committerLars Wirzenius <liw@liw.fi>2018-01-10 16:08:04 +0200
commit0d03db771b48f7d90cf96560c32048001809e84f (patch)
tree0dd2afc2fef804df1e501c60000d0d08e1773e50 /jwt-decode
parent9fdf74a1b44f76a3749ae4111472647d79cf3f6a (diff)
downloadextrautils-0d03db771b48f7d90cf96560c32048001809e84f.tar.gz
Add: a bunch of new scripts
Diffstat (limited to 'jwt-decode')
-rwxr-xr-xjwt-decode38
1 files changed, 38 insertions, 0 deletions
diff --git a/jwt-decode b/jwt-decode
new file mode 100755
index 0000000..b57362b
--- /dev/null
+++ b/jwt-decode
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+import json
+import sys
+
+import Crypto.PublicKey.RSA
+
+import jwt
+
+
+def catf(f):
+ return f.read()
+
+
+def cat(filename):
+ with open(filename, 'r') as f:
+ return catf(f)
+
+
+if len(sys.argv) == 1:
+ token = catf(sys.stdin).strip()
+ obj = jwt.decode(token, verify=False)
+elif len(sys.argv) == 2:
+ token = cat(sys.argv[1]).strip()
+ obj = jwt.decode(token, verify=False)
+elif len(sys.argv) == 3:
+ token = cat(sys.argv[1]).strip()
+ pubkey_text = cat(sys.argv[2])
+ opts = {
+ 'verify_aud': False,
+ 'verify_iss': False,
+ }
+ obj = jwt.decode(token, verify=True, key=pubkey_text, options=opts)
+else:
+ assert 0
+
+json.dump(obj, sys.stdout, indent=4)
+sys.stdout.write('\n')