jwtscope 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. jwtscope-1.0.0/.gitignore +22 -0
  2. jwtscope-1.0.0/.release-please-manifest.json +3 -0
  3. jwtscope-1.0.0/CHANGELOG.md +70 -0
  4. jwtscope-1.0.0/LICENSE.md +8 -0
  5. jwtscope-1.0.0/PKG-INFO +471 -0
  6. jwtscope-1.0.0/README.md +426 -0
  7. jwtscope-1.0.0/RELEASING.md +76 -0
  8. jwtscope-1.0.0/SECURITY.md +48 -0
  9. jwtscope-1.0.0/pyproject.toml +112 -0
  10. jwtscope-1.0.0/release-please-config.json +19 -0
  11. jwtscope-1.0.0/scripts/branch_coverage.py +40 -0
  12. jwtscope-1.0.0/scripts/check_pr_title.py +61 -0
  13. jwtscope-1.0.0/scripts/live_check.py +92 -0
  14. jwtscope-1.0.0/scripts/smoke_wheel.py +214 -0
  15. jwtscope-1.0.0/src/jwtscope/__init__.py +10 -0
  16. jwtscope-1.0.0/src/jwtscope/__main__.py +8 -0
  17. jwtscope-1.0.0/src/jwtscope/algorithms.yaml +51 -0
  18. jwtscope-1.0.0/src/jwtscope/claim_values.yaml +113 -0
  19. jwtscope-1.0.0/src/jwtscope/claims.yaml +131 -0
  20. jwtscope-1.0.0/src/jwtscope/claimspec.py +55 -0
  21. jwtscope-1.0.0/src/jwtscope/cli.py +337 -0
  22. jwtscope-1.0.0/src/jwtscope/cli_common.py +248 -0
  23. jwtscope-1.0.0/src/jwtscope/cli_crypto.py +682 -0
  24. jwtscope-1.0.0/src/jwtscope/config.py +485 -0
  25. jwtscope-1.0.0/src/jwtscope/constants.py +24 -0
  26. jwtscope-1.0.0/src/jwtscope/defaults.yaml +49 -0
  27. jwtscope-1.0.0/src/jwtscope/encode.py +198 -0
  28. jwtscope-1.0.0/src/jwtscope/errors.py +68 -0
  29. jwtscope-1.0.0/src/jwtscope/fetch.py +247 -0
  30. jwtscope-1.0.0/src/jwtscope/inputs.py +217 -0
  31. jwtscope-1.0.0/src/jwtscope/jwe.py +221 -0
  32. jwtscope-1.0.0/src/jwtscope/jws.py +165 -0
  33. jwtscope-1.0.0/src/jwtscope/keys.py +741 -0
  34. jwtscope-1.0.0/src/jwtscope/log.py +33 -0
  35. jwtscope-1.0.0/src/jwtscope/mcp_server.py +377 -0
  36. jwtscope-1.0.0/src/jwtscope/mldsa.py +176 -0
  37. jwtscope-1.0.0/src/jwtscope/profiles.py +403 -0
  38. jwtscope-1.0.0/src/jwtscope/profiles.yaml +283 -0
  39. jwtscope-1.0.0/src/jwtscope/py.typed +0 -0
  40. jwtscope-1.0.0/src/jwtscope/redact.py +36 -0
  41. jwtscope-1.0.0/src/jwtscope/remote.py +346 -0
  42. jwtscope-1.0.0/src/jwtscope/render.py +349 -0
  43. jwtscope-1.0.0/src/jwtscope/report.py +465 -0
  44. jwtscope-1.0.0/src/jwtscope/summary.py +176 -0
  45. jwtscope-1.0.0/src/jwtscope/timezones.py +62 -0
  46. jwtscope-1.0.0/src/jwtscope/tokens.py +287 -0
  47. jwtscope-1.0.0/src/jwtscope/verify.py +308 -0
  48. jwtscope-1.0.0/tests/__init__.py +0 -0
  49. jwtscope-1.0.0/tests/conftest.py +470 -0
  50. jwtscope-1.0.0/tests/golden/adfs_2012r2.json +176 -0
  51. jwtscope-1.0.0/tests/golden/adfs_2012r2.txt +36 -0
  52. jwtscope-1.0.0/tests/golden/adfs_2016.json +192 -0
  53. jwtscope-1.0.0/tests/golden/adfs_2016.txt +35 -0
  54. jwtscope-1.0.0/tests/golden/entra_v1_overage.json +294 -0
  55. jwtscope-1.0.0/tests/golden/entra_v1_overage.txt +54 -0
  56. jwtscope-1.0.0/tests/golden/entra_v2_app.json +213 -0
  57. jwtscope-1.0.0/tests/golden/entra_v2_app.txt +38 -0
  58. jwtscope-1.0.0/tests/golden/graph.json +275 -0
  59. jwtscope-1.0.0/tests/golden/graph.txt +50 -0
  60. jwtscope-1.0.0/tests/https_server.py +156 -0
  61. jwtscope-1.0.0/tests/idp.py +204 -0
  62. jwtscope-1.0.0/tests/test_claimspec.py +63 -0
  63. jwtscope-1.0.0/tests/test_cli_decode.py +152 -0
  64. jwtscope-1.0.0/tests/test_cli_fetch.py +266 -0
  65. jwtscope-1.0.0/tests/test_cli_options.py +218 -0
  66. jwtscope-1.0.0/tests/test_cli_safety.py +253 -0
  67. jwtscope-1.0.0/tests/test_cli_smoke.py +20 -0
  68. jwtscope-1.0.0/tests/test_config.py +207 -0
  69. jwtscope-1.0.0/tests/test_conformance.py +214 -0
  70. jwtscope-1.0.0/tests/test_decrypt.py +178 -0
  71. jwtscope-1.0.0/tests/test_encode.py +449 -0
  72. jwtscope-1.0.0/tests/test_fetch.py +267 -0
  73. jwtscope-1.0.0/tests/test_idp.py +205 -0
  74. jwtscope-1.0.0/tests/test_inputs.py +247 -0
  75. jwtscope-1.0.0/tests/test_jwe.py +225 -0
  76. jwtscope-1.0.0/tests/test_jws.py +154 -0
  77. jwtscope-1.0.0/tests/test_keys.py +417 -0
  78. jwtscope-1.0.0/tests/test_log.py +13 -0
  79. jwtscope-1.0.0/tests/test_mcp_server.py +326 -0
  80. jwtscope-1.0.0/tests/test_mldsa.py +131 -0
  81. jwtscope-1.0.0/tests/test_profiles.py +310 -0
  82. jwtscope-1.0.0/tests/test_redact.py +40 -0
  83. jwtscope-1.0.0/tests/test_remote.py +472 -0
  84. jwtscope-1.0.0/tests/test_render.py +312 -0
  85. jwtscope-1.0.0/tests/test_report.py +264 -0
  86. jwtscope-1.0.0/tests/test_scripts.py +217 -0
  87. jwtscope-1.0.0/tests/test_summary.py +146 -0
  88. jwtscope-1.0.0/tests/test_tokens.py +271 -0
  89. jwtscope-1.0.0/tests/test_verify.py +643 -0
  90. jwtscope-1.0.0/tests/vectors/README.md +11 -0
  91. jwtscope-1.0.0/tests/vectors/rfc7520.json +114 -0
  92. jwtscope-1.0.0/tests/vectors/rfc8037.json +15 -0
  93. jwtscope-1.0.0/tests/vectors/rfc9964.json +17 -0
  94. jwtscope-1.0.0/uv.lock +1778 -0
@@ -0,0 +1,22 @@
1
+ .DS_Store
2
+ Thumbs.db
3
+ *.log
4
+ *.orig
5
+ __pycache__/
6
+ *.py[cod]
7
+ .venv/
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ .coverage
12
+ .coverage.*
13
+ coverage.xml
14
+ htmlcov/
15
+ .pytest_cache/
16
+ .mypy_cache/
17
+ .ruff_cache/
18
+ .hypothesis/
19
+ Claude outputs/
20
+ coverage.json
21
+ .smoke/
22
+ .sbom/
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "1.0.0"
3
+ }
@@ -0,0 +1,70 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [1.0.0](https://github.com/SCGIS-Wales/jwt-decoder/compare/v0.1.0...v1.0.0) (2026-12-03)
8
+
9
+
10
+ ### ⚠ BREAKING CHANGES
11
+
12
+ * JOSE layer on joserfc with JWE and post quantum signatures ([#9](https://github.com/SCGIS-Wales/jwt-decoder/issues/9))
13
+
14
+ ### Features
15
+
16
+ * issuer profiles, custom claims and friendlier output ([#10](https://github.com/SCGIS-Wales/jwt-decoder/issues/10)) ([a98bedd](https://github.com/SCGIS-Wales/jwt-decoder/commit/a98bedd071c23832466b8a3e8396b473341b8374))
17
+ * JOSE layer on joserfc with JWE and post quantum signatures ([#9](https://github.com/SCGIS-Wales/jwt-decoder/issues/9)) ([fbe3dd7](https://github.com/SCGIS-Wales/jwt-decoder/commit/fbe3dd7c071ba1895772dbece8e80d4de01f2265))
18
+ * verify with keys from OpenID Connect discovery or a JWKS URL ([#11](https://github.com/SCGIS-Wales/jwt-decoder/issues/11)) ([98d37d2](https://github.com/SCGIS-Wales/jwt-decoder/commit/98d37d2f9420d7e70399d516f2a3ad83160e022a))
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * security and resilience defects ([#8](https://github.com/SCGIS-Wales/jwt-decoder/issues/8)) ([257d898](https://github.com/SCGIS-Wales/jwt-decoder/commit/257d898420658dfd29a745a2daae77a8b2cfca2f))
24
+
25
+ ## [0.1.0] - 2026-12-02 (not published)
26
+
27
+ First version of `jwtscope`, a Python rewrite of the Rust `jwt-cli` 6.2.0 that this
28
+ repository was forked from. It was never published to PyPI. The Rust code is kept at
29
+ tag `rust-6.2.0` for reference only: it is unsupported and its crates have published
30
+ security advisories.
31
+
32
+ ### Added
33
+
34
+ - `jwtd` and `jwtscope` commands. `jwtd <token>` decodes without a subcommand; `jwtd`
35
+ alone reads a pipe or opens a hidden paste prompt that accepts tokens longer than the
36
+ terminal line limit; `jwtd -c` reads the clipboard.
37
+ - Tolerant extraction of tokens pasted with a `Bearer` prefix, an `Authorization:`
38
+ header, quotes, line wraps, a byte order mark or a JSON token response.
39
+ - JWE recognition (header shown, payload stated as encrypted) and a specific message
40
+ for opaque tokens.
41
+ - Descriptions for every registered JOSE algorithm: JWS (HS, RS, PS, ES incl. ES256K,
42
+ EdDSA, Ed25519, Ed448, ML-DSA) and JWE key management and content encryption.
43
+ - Every time claim shown as epoch, absolute and relative time, with a status line
44
+ (`ACTIVE`, `EXPIRED`, `NOT YET VALID`, `NO EXPIRY`, `UNKNOWN`).
45
+ - `--json` output with a stable, versioned schema.
46
+ - `jwtd verify` with public keys (PEM, DER, X.509 certificate, JWK, JWKS) or HMAC secrets
47
+ from an environment variable or file, for HS256/384/512, RS256/384/512, PS256/384/512,
48
+ ES256, ES256K, ES384, ES512 and EdDSA (Ed25519 and Ed448).
49
+ - `jwtd encode` to sign tokens with the same algorithm set from PEM, DER or JWK keys.
50
+ - `jwtd mcp`, an MCP server with read only `decode_jwt`, `verify_jwt` and opt-in
51
+ `decode_jwt_from_clipboard` tools.
52
+ - YAML configuration, `jwtd config show|path` and `jwtd completion bash|zsh|fish`.
53
+
54
+ ### Changed (breaking, relative to `jwt-cli` 6.2.0)
55
+
56
+ - The command is `jwtd` (or `jwtscope`) instead of `jwt`, installed with pip or uv.
57
+ - Decoding never implies trust: the first line always states whether the signature was
58
+ verified, and verification is a separate `verify` command.
59
+ - Leeway defaults to 0 seconds instead of a hidden 1000 seconds.
60
+ - `--secret` is gone. Secrets come from `--secret-env` or `--secret-file`; keys from
61
+ `--key` or `--jwks`.
62
+ - The algorithm is taken from the key type, never from the token alone.
63
+ - Dates are always shown; `--date` is replaced by `--tz`.
64
+ - `--out` is removed; use shell redirection.
65
+ - Exit codes: 0 success, 1 not a decodable token, 2 usage error, 3 verification failed,
66
+ 4 key, configuration or input error.
67
+
68
+ ### Removed
69
+
70
+ - The Rust implementation, Travis CI and AppVeyor configuration.
@@ -0,0 +1,8 @@
1
+ Copyright 2017 Mike Engel <mike@mike-engel.com>
2
+ Copyright 2026 Dejan Gregor and jwtscope contributors
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,471 @@
1
+ Metadata-Version: 2.5
2
+ Name: jwtscope
3
+ Version: 1.0.0
4
+ Summary: Decode, inspect and verify JSON Web Tokens from the command line or an MCP client.
5
+ Project-URL: Homepage, https://github.com/SCGIS-Wales/jwt-decoder
6
+ Project-URL: Issues, https://github.com/SCGIS-Wales/jwt-decoder/issues
7
+ Author: Dejan Gregor
8
+ License-Expression: MIT
9
+ License-File: LICENSE.md
10
+ Keywords: cli,jose,jwe,jws,jwt,mcp,oauth,oidc
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
+ Classifier: Topic :: Security :: Cryptography
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.13
23
+ Requires-Dist: click<9,>=8.5.1
24
+ Requires-Dist: pyyaml<7,>=6.0.4
25
+ Requires-Dist: tzdata>=2026.6; sys_platform == 'win32'
26
+ Provides-Extra: all
27
+ Requires-Dist: cryptography>=51.0.0; extra == 'all'
28
+ Requires-Dist: joserfc<2,>=1.8.0; extra == 'all'
29
+ Requires-Dist: mcp<3,>=2.3.0; extra == 'all'
30
+ Requires-Dist: truststore<1,>=0.10.5; extra == 'all'
31
+ Provides-Extra: crypto
32
+ Requires-Dist: cryptography>=51.0.0; extra == 'crypto'
33
+ Requires-Dist: joserfc<2,>=1.8.0; extra == 'crypto'
34
+ Requires-Dist: truststore<1,>=0.10.5; extra == 'crypto'
35
+ Provides-Extra: mcp
36
+ Requires-Dist: cryptography>=51.0.0; extra == 'mcp'
37
+ Requires-Dist: joserfc<2,>=1.8.0; extra == 'mcp'
38
+ Requires-Dist: mcp<3,>=2.3.0; extra == 'mcp'
39
+ Requires-Dist: truststore<1,>=0.10.5; extra == 'mcp'
40
+ Provides-Extra: verify
41
+ Requires-Dist: cryptography>=51.0.0; extra == 'verify'
42
+ Requires-Dist: joserfc<2,>=1.8.0; extra == 'verify'
43
+ Requires-Dist: truststore<1,>=0.10.5; extra == 'verify'
44
+ Description-Content-Type: text/markdown
45
+
46
+ # jwtscope
47
+
48
+ Decode, inspect, verify, sign, encrypt and decrypt JSON Web Tokens from the command line, or let an AI agent inspect them through MCP.
49
+
50
+ ```text
51
+ $ jwtd
52
+ Paste token, then press Enter (input hidden):
53
+ Read 1194 characters.
54
+ JWT RS256 signature NOT verified (decode only)
55
+
56
+ Summary
57
+ Issuer Microsoft Entra ID v2.0, tenant 8d3f0c9e-5b1a-4c7d-9e2f-0a1b2c3d4e5f
58
+ Token access token, application permissions (no user) for api://orders
59
+ Client 3f9a1c2e-7b4d-4e8f-a1b2-c3d4e5f60718, client authentication: certificate
60
+ Granted roles Orders.Read.All, Orders.Write
61
+ Lifetime 1 h, issued 1 min ago, expires in 59 min
62
+ Verify with jwtd verify --oidc https://login.microsoftonline.com/<your tenant id>/v2.0 --aud
63
+ <your API>
64
+
65
+ Header
66
+ typ JWT
67
+ alg RS256 RSASSA-PKCS1-v1_5 using SHA-256
68
+ kid entra-key-1
69
+ x5t entra-key-1
70
+
71
+ Claims
72
+ aud api://orders Audience
73
+ iss https://login.microsoftonline.com/8d3f0c9e-5b1a-4c7d-9e2f-0a1b2c3d4e5f/v2.0 Issuer
74
+ iat 1796216340 2026-12-02T12:59:00+00:00 Issued at, 1 min ago
75
+ nbf 1796216340 2026-12-02T12:59:00+00:00 Not before, 1 min ago
76
+ exp 1796219940 2026-12-02T13:59:00+00:00 Expires in 59 min
77
+ aio E2RgYPhpZ3l1cmVkU2Vzc2lvbkRhdGE= Session data (internal)
78
+ azp 3f9a1c2e-7b4d-4e8f-a1b2-c3d4e5f60718 Authorized party
79
+ azpacr 2 Client authentication method: certificate
80
+ idtyp app Token type (application or user): application only, no user
81
+ oid 6c1d2e3f-4a5b-4c6d-8e7f-90a1b2c3d4e5 Object identifier
82
+ rh 0.ARoAQ29udG9zbw. Refresh hint (internal)
83
+ roles Orders.Read.All, Orders.Write Roles
84
+ sub 6c1d2e3f-4a5b-4c6d-8e7f-90a1b2c3d4e5 Subject
85
+ tid 8d3f0c9e-5b1a-4c7d-9e2f-0a1b2c3d4e5f Tenant identifier
86
+ uti c3VwZXJ1bmlxdWU Token identifier (internal)
87
+ ver 2.0 Token version
88
+ costCentre 4711 custom claim
89
+
90
+ Status
91
+ ACTIVE, expires in 59 min
92
+ ```
93
+
94
+ ## Install
95
+
96
+ ```bash
97
+ # Install the command as an isolated tool; provides jwtd and jwtscope (decode only)
98
+ uv tool install jwtscope
99
+ # Or install with pip into the current environment
100
+ pip install jwtscope
101
+ # Add verification, signing, encryption and decryption (joserfc and cryptography)
102
+ pip install "jwtscope[crypto]"
103
+ # Add the MCP server as well (includes crypto)
104
+ pip install "jwtscope[mcp]"
105
+ ```
106
+
107
+ The base install depends only on click and PyYAML. Python 3.13 or later is required.
108
+ `jwtscope[verify]` remains as another name for `jwtscope[crypto]`.
109
+
110
+ ## Supported algorithms
111
+
112
+ | Purpose | Algorithms |
113
+ |---|---|
114
+ | Decode and describe (JWS) | Every registered JWS algorithm: HS256/384/512, RS256/384/512, PS256/384/512, ES256, ES256K, ES384, ES512, EdDSA, Ed25519, Ed448, ML-DSA-44/65/87; unregistered values are flagged |
115
+ | Decode and describe (JWE) | RSA1_5, RSA-OAEP, RSA-OAEP-256/384/512, A128KW/A192KW/A256KW, dir, ECDH-ES (+A128KW/A192KW/A256KW), A128GCMKW/A192GCMKW/A256GCMKW, PBES2-HS256+A128KW/HS384+A192KW/HS512+A256KW; enc A128CBC-HS256, A192CBC-HS384, A256CBC-HS512, A128GCM, A192GCM, A256GCM |
116
+ | Verify and sign | HS256, HS384, HS512, RS256, RS384, RS512, PS256, PS384, PS512, ES256 (P-256), ES256K (secp256k1), ES384 (P-384), ES512 (P-521), EdDSA (Ed25519 and Ed448), Ed25519 and Ed448 (RFC 9864), ML-DSA-44, ML-DSA-65 and ML-DSA-87 (FIPS 204 post quantum signatures, RFC 9964 AKP keys) |
117
+ | Encrypt and decrypt | Key management RSA-OAEP, RSA-OAEP-256/384/512, ECDH-ES and ECDH-ES+A128KW/A192KW/A256KW (P-256, P-384, P-521, X25519, X448), A128KW/A192KW/A256KW, A128GCMKW/A192GCMKW/A256GCMKW, dir, PBES2-HS256+A128KW/HS384+A192KW/HS512+A256KW; content A128GCM, A192GCM, A256GCM, A128CBC-HS256, A192CBC-HS384, A256CBC-HS512 |
118
+ | Decrypt only | RSA1_5, with a warning (switch it off with `jwe.allow_rsa1_5_decrypt: false`); compressed content (`zip: DEF`) |
119
+
120
+ `none` can never be verified or signed. jwtscope never encrypts with RSA1_5 and never
121
+ compresses what it encrypts. The tests replay the published examples of RFC 7520, RFC 8037
122
+ and RFC 9964, and exchange tokens with PyJWT and jwcrypto in both directions.
123
+
124
+ ## Decode a token
125
+
126
+ ```bash
127
+ # Paste at a hidden prompt (works for tokens longer than the terminal line limit)
128
+ jwtd
129
+ # Decode a token given as an argument; a Bearer prefix or Authorization header is fine
130
+ jwtd "Authorization: Bearer eyJhbGciOi..."
131
+ # Decode the token on the clipboard (pbpaste, PowerShell Get-Clipboard, wl-paste or xclip)
132
+ jwtd -c
133
+ # Decode from a pipe, or a JSON token response containing access_token or id_token
134
+ curl -s https://idp.example/token -d ... | jwtd
135
+ # Decode a token saved in a file (a byte order mark and Windows line endings are fine)
136
+ jwtd @token.txt
137
+ # Print the report as JSON, with times in a named zone or a fixed offset
138
+ jwtd --json --tz Europe/London "$TOKEN"
139
+ # Print single values for scripts: text as is, lists and objects as JSON
140
+ jwtd --get oid --get header.kid "$TOKEN"
141
+ # Exit with status 5 when the token is expired or not yet valid
142
+ jwtd --require-active "$TOKEN" > /dev/null && echo "still valid"
143
+ ```
144
+
145
+ `jwtd decode [TOKEN]` is the explicit form. Options: `-c/--clipboard`, `--json`,
146
+ `--get NAME` (repeatable; a claim, or `header.NAME`), `--require-active`, `--no-summary`,
147
+ `--tz ZONE` (`utc`, `local`, an offset such as `+02:00`, or an IANA name such as
148
+ `Europe/London`), `--no-colour` (alias `--no-color`), `--config FILE`. A bare file name is
149
+ not read as a token: `jwtd token.txt` answers "token.txt is a file; to read the token in it,
150
+ use @token.txt". Colour is used only on a terminal and never when `NO_COLOR` is set. Claim
151
+ values are escaped so a token cannot inject terminal control sequences; `--get` prints raw
152
+ values to a pipe and escaped values on a terminal. A missing `--get` value exits with
153
+ status 1 and prints nothing.
154
+
155
+ ### What the report shows
156
+
157
+ * **Summary:** who issued the token, what kind it is and for which audience, the user and
158
+ how they signed in, the client and how it authenticated, the scopes or roles granted, the
159
+ lifetime, notes about the issuer, and how to verify it. `--no-summary` or
160
+ `output.summary: false` leaves it out.
161
+ * **Recognised issuers:** Microsoft Entra ID v1.0 and v2.0 (national clouds, External ID
162
+ and Azure AD B2C included), Microsoft Graph, AD FS 2012 R2 and AD FS 2016 or later, Okta,
163
+ Auth0, Keycloak, Google, Amazon Cognito, and any access token that follows RFC 9068.
164
+ * **Claims:** every claim, labelled. Values with a documented meaning are explained, for
165
+ example `azpacr 2` as "Client authentication method: certificate". Claims nobody
166
+ registered are marked `custom claim` and shown in full, whatever their type: nested
167
+ values become indented trees, and long values wrap without being cut.
168
+ * **Times:** NumericDate claims are dated in your zone. ISO 8601 text, such as the AD FS
169
+ 2012 R2 `auth_time`, is dated with a note saying so. An `iat` in the future is flagged.
170
+ * **Clean input:** zero width spaces, soft hyphens and byte order marks that copying adds
171
+ to a token are removed, with a warning that says how many.
172
+
173
+ Add labels with `claims`, value descriptions with `claim_values` and your own issuers with
174
+ `profiles` in the configuration file. The profile rule language is described at the top of
175
+ [profiles.yaml](src/jwtscope/profiles.yaml); your profiles are tried before the packaged ones.
176
+
177
+ A mistyped command is caught rather than decoded: `jwtd verfy ...` answers
178
+ "unknown command 'verfy'; did you mean 'verify'?". `jwtd help [COMMAND]` shows help.
179
+ Error messages never repeat a token: anything shaped like one is shown as
180
+ `<token redacted>`. Output that a terminal or file cannot encode (for example a legacy
181
+ Windows code page) is escaped instead of failing, and `--json` then uses ASCII escapes so
182
+ the JSON stays valid. Add `--debug` (or set `JWTSCOPE_DEBUG=1`) to see a traceback after an
183
+ unexpected error.
184
+
185
+ ## Verify a token
186
+
187
+ ```bash
188
+ # Verify with a PEM or DER public key, or an X.509 certificate
189
+ jwtd verify "$TOKEN" --key public.pem
190
+ # Verify with a JWKS file; the key is chosen by the token's kid
191
+ jwtd verify "$TOKEN" --jwks jwks.json --aud api://orders --iss https://login.example.com/tenant/v2.0
192
+ # Verify an HMAC token with a secret held in an environment variable or file
193
+ JWT_SECRET=... jwtd verify "$TOKEN" --secret-env JWT_SECRET
194
+ jwtd verify "$TOKEN" --secret-file secret.b64 --secret-encoding base64
195
+ # Fetch the keys by OpenID Connect discovery, which also pins the issuer (Entra ID v2.0)
196
+ jwtd verify "$TOKEN" --oidc https://login.microsoftonline.com/$TENANT_ID/v2.0 --aud api://orders
197
+ # Fetch a key set from a URL and pin the tenant (Entra ID v1.0 tokens)
198
+ jwtd verify "$TOKEN" --jwks-url https://login.microsoftonline.com/$TENANT_ID/discovery/keys --tenant $TENANT_ID
199
+ # AD FS 2016 or later: discovery names both issuers AD FS uses
200
+ jwtd verify "$TOKEN" --oidc https://adfs.contoso.com/adfs --aud "$RELYING_PARTY_ID"
201
+ # AD FS 2012 R2: give both token signing certificates during a rollover
202
+ jwtd verify "$TOKEN" --key adfs-old.cer --key adfs-new.cer --aud "$RELYING_PARTY_ID"
203
+ # Require claims: present, equal to text (or one of a list or scope words), or equal as JSON
204
+ jwtd verify "$TOKEN" --oidc "$ISSUER" --require-claim tid --require-claim scp=orders.read --require-claim 'acct:=0'
205
+ ```
206
+
207
+ Give keys with `--key`, `--jwks` and `--jwks-url` (all repeatable) or `--oidc`, which
208
+ combine, or an HMAC secret with `--secret-env` or `--secret-file`. The key is chosen by the
209
+ token's `kid`, then `x5t`,
210
+ then `x5t#S256`, so an AD FS signing certificate rollover works when both certificates are
211
+ given. Other options: `--secret-encoding [utf8|base64|base64url|hex]`, `--alg ALG`
212
+ (repeatable; narrows the allow list), `--aud` and `--iss` (repeatable; one match is enough),
213
+ `--tenant TENANT_ID` (repeatable; accepts that tenant's Microsoft Entra ID issuers, v1.0,
214
+ v2.0 and the national clouds), `--require-claim CLAIM` (repeatable; `NAME`, `NAME=TEXT` or
215
+ `NAME:=JSON`, added to `verify.required_claims`),
216
+ `--leeway SECONDS` (default 0), `--ignore-exp`, `--decrypt-key FILE` (repeatable) and
217
+ `--decrypt-password-env NAME` for encrypted tokens, plus every `decode` option. The algorithm
218
+ is derived from the key type, so a token cannot choose HS256 against an RSA key. Verification
219
+ takes public keys and certificates only: a file holding a private key is refused. On failure the report is still printed, headed "verification FAILED" with the
220
+ reason, and the exit code is 3. In `--json` output `signature.state` is `verified`,
221
+ `failed` or `not_checked`, `signature.detail` holds the reason, and `signature.checks`
222
+ marks the check that failed, for example `"exp": "failed: token expired"`. With `--get`,
223
+ values are printed only when verification succeeds.
224
+
225
+ A tenant ID must be the Directory (tenant) ID, a GUID; a domain name is refused with that
226
+ hint. When an Entra token's signature holds but neither `--tenant` nor `--iss` was given,
227
+ the report warns that a token from any tenant would have passed. A Microsoft Graph token
228
+ cannot be verified outside Graph, because its signature covers a hash of the `nonce`
229
+ header: the report says that such a failure is expected.
230
+
231
+ ### Keys from the issuer
232
+
233
+ `--oidc ISSUER_URL` reads `ISSUER_URL/.well-known/openid-configuration` (the full discovery
234
+ URL works too), checks that the document names exactly that issuer, as OpenID Connect
235
+ Discovery requires, and verifies with the keys at its `jwks_uri`. The token's `iss` must then
236
+ be that issuer, or the `access_token_issuer` an AD FS document also names. The Entra ID
237
+ `common`, `organizations` and `consumers` documents name no single issuer, so add `--tenant`
238
+ or `--iss` with them. Where a document names an issuer other than its own address (Entra ID
239
+ v1.0, Azure AD B2C user flows), `--oidc` refuses it and the message gives its `jwks_uri` for
240
+ `--jwks-url`; pin the issuer with `--iss` or `--tenant` then. Each profile's "Verify with"
241
+ row shows the right command, with placeholders for your own values.
242
+
243
+ * **Transport:** HTTPS only, also for redirects (at most three). Certificates are checked
244
+ against the operating system's trust store, which is where corporate TLS inspection
245
+ installs its root; `SSL_CERT_FILE` names a CA bundle to use instead. `HTTPS_PROXY` and
246
+ `NO_PROXY` are honoured. Connection errors, timeouts, HTTP 429 and 5xx are retried with
247
+ backoff, after `Retry-After` when the server sends one. Responses above
248
+ `limits.max_fetch_bytes` are refused.
249
+ * **Cache:** only the public keys and the discovery `issuer`, `jwks_uri` and
250
+ `access_token_issuer` are stored, in files only you can read: `~/.cache/jwtscope` (or
251
+ `$XDG_CACHE_HOME/jwtscope`) on Linux, `~/Library/Caches/jwtscope` on macOS and
252
+ `%LOCALAPPDATA%\jwtscope\Cache` on Windows; `JWTSCOPE_CACHE_DIR` overrides it. A copy is
253
+ reused for an hour, or less when the server's `Cache-Control` says so. A token whose `kid`
254
+ is not in the cached keys fetches them again, at most once a minute, so key rotation needs
255
+ no action. When the issuer cannot be reached, keys up to a day old are used with a
256
+ warning.
257
+ * **Safety:** the URL always comes from you, never from the token. A key set holding
258
+ private or symmetric key material is refused whole. Fetch problems exit with status 4 and
259
+ say what failed, for example `cannot fetch https://idp.example/keys: HTTP 503 Service
260
+ Unavailable (tried 4 times)`.
261
+
262
+ ## Decrypt a token
263
+
264
+ ```bash
265
+ # Decrypt with a private key (PEM, DER or private JWK); the report shows both layers
266
+ jwtd decrypt "$TOKEN" --key private.pem
267
+ # Decrypt with a shared key for dir, AES key wrap or AES GCM key wrap
268
+ jwtd decrypt "$TOKEN" --secret-env JWE_KEY --secret-encoding base64url
269
+ # Decrypt a password protected (PBES2) token
270
+ JWE_PASSWORD=... jwtd decrypt "$TOKEN" --password-env JWE_PASSWORD
271
+ # Decrypt, then verify the inner signature, in one step
272
+ jwtd verify "$TOKEN" --decrypt-key private.pem --jwks jwks.json --aud api://orders
273
+ ```
274
+
275
+ Options: `--key FILE` and `--jwks FILE` (repeatable; each suitable key is tried),
276
+ `--key-password-env NAME`, `--secret-env NAME`, `--secret-file FILE`, `--secret-encoding`,
277
+ `--password-env NAME`, plus every `decode` option. `Header` shows the outer JWE header,
278
+ `Encryption` the algorithms and the key that worked, and `Inner header` the signed token's
279
+ header when the content is a nested JWT; claims, times and status come from the decrypted
280
+ content. `jwtd decrypt` never verifies the inner signature: use `jwtd verify --decrypt-key`
281
+ for that. Content that is not a signed token is shown with the warning "token is encrypted
282
+ but not signed" and can never pass `verify`, because anyone holding the recipient's public
283
+ key could have made it. A wrong key exits with code 3 and names the reason.
284
+
285
+ ## Sign or encrypt a token
286
+
287
+ ```bash
288
+ # Sign with a private key; the algorithm defaults to one that suits the key
289
+ jwtd encode --key private.pem --sub alice --aud api://orders --exp 1h
290
+ # Choose the algorithm, add claims and headers, and read base claims from a file
291
+ jwtd encode --key ec-p256k.pem --alg ES256K --payload @claims.json --claim 'roles:=["admin"]' --kid k1
292
+ # Sign with an HMAC secret from the environment (at least 32 bytes for HS256)
293
+ jwtd encode --secret-env JWT_SECRET --alg HS512 --iss https://issuer.example --no-exp
294
+ # Sign, then encrypt to a recipient's public key or certificate (a nested JWT)
295
+ jwtd encode --key private.pem --sub alice --encrypt-to recipient.crt
296
+ # Choose the key management and content algorithms, or encrypt with a password instead
297
+ jwtd encode --key private.pem --encrypt-to recipient.pem --key-alg ECDH-ES+A256KW --enc A128GCM
298
+ jwtd encode --key private.pem --encrypt-password-env JWE_PASSWORD
299
+ ```
300
+
301
+ Options: `--alg ALG`, `--key FILE` (PEM, DER or private JWK, ML-DSA AKP keys included),
302
+ `--key-password-env NAME`,
303
+ `--secret-env NAME`, `--secret-file FILE`, `--secret-encoding`, `--payload JSON|@FILE|-`,
304
+ `--claim` and `--header` (repeatable; `NAME=TEXT` always sets text, `NAME:=JSON` sets a
305
+ number, `true`, `false`, `null`, a list or an object, and dotted names such as `extn.dept`
306
+ stay one claim),
307
+ `--iss`, `--sub`, `--aud` (repeatable), `--jti`, `--kid`, `--typ`, `--exp DURATION`
308
+ (for example `15m`, `2h`, `7d`; default from configuration), `--no-exp`, `--nbf DURATION`,
309
+ `--no-iat`, `--encrypt-to FILE` (public key, certificate, public JWK or shared `oct` JWK),
310
+ `--encrypt-password-env NAME`, `--key-alg ALG` (default `encode.default_key_algorithm` when the
311
+ key suits it, otherwise the first suitable entry of `jwe.allowed_key_algorithms`), `--enc ENC`
312
+ (default `encode.default_content_algorithm`), `--config FILE`. Signing and encryption are not
313
+ available through MCP.
314
+
315
+ ## Use from an AI agent
316
+
317
+ ```json
318
+ {
319
+ "mcpServers": {
320
+ "jwtscope": {
321
+ "command": "uvx",
322
+ "args": ["--from", "jwtscope[mcp]", "jwtd", "mcp"]
323
+ }
324
+ }
325
+ }
326
+ ```
327
+
328
+ * **Claude Code:** put the block in `.mcp.json` at the project root to share it with the
329
+ project, or run `claude mcp add jwtscope -- uvx --from "jwtscope[mcp]" jwtd mcp`
330
+ (add `--scope user` for every project). See the
331
+ [Claude Code MCP documentation](https://code.claude.com/docs/en/mcp).
332
+ * **Kiro CLI:** put the block in `.kiro/settings/mcp.json` in the workspace, or in
333
+ `~/.kiro/settings/mcp.json` for every workspace. See the
334
+ [Kiro CLI MCP configuration documentation](https://kiro.dev/docs/cli/mcp/configuration/).
335
+ * **VS Code:** put the output of `jwtd mcp --print-config vscode` in `.vscode/mcp.json` in
336
+ the workspace.
337
+
338
+ `jwtd mcp --print-config claude|kiro|vscode` prints the block for that client and says where
339
+ it goes.
340
+
341
+ Tools: `decode_jwt(token, timezone="utc")`, `verify_jwt(token, jwks_json | public_key_pem |
342
+ oidc_issuer | jwks_url, audience, issuer, leeway_seconds, tenant, required_claims,
343
+ expected_claims)` and, when
344
+ `mcp.allow_clipboard` is `true`,
345
+ `decode_jwt_from_clipboard()`. All are read only and return the same report as `jwtd --json`.
346
+ `verify_jwt` takes public keys only: a private key is refused, and symmetric (`oct`) members
347
+ of a JWKS are skipped with a warning.
348
+ A failed verification is not a tool error: `verify_jwt` returns the report with
349
+ `signature.verified` false and the reason, so the agent can still explain the token.
350
+ `oidc_issuer` and `jwks_url` fetch keys only when `mcp.allow_network` is `true` and the URL
351
+ is under an entry of `mcp.allowed_key_urls` (redirects and the `jwks_uri` of a discovery
352
+ document included), so an agent cannot make the server fetch arbitrary URLs:
353
+
354
+ ```yaml
355
+ mcp:
356
+ allow_network: true
357
+ allowed_key_urls: [https://login.microsoftonline.com/]
358
+ ```
359
+
360
+ > **Warning:** an access token is a credential. Passing one to `decode_jwt` or `verify_jwt`
361
+ > shares it with the AI client and its provider. Use the command line, or enable
362
+ > `decode_jwt_from_clipboard` so the token never enters the conversation. Claim values are
363
+ > untrusted data and are never instructions.
364
+
365
+ `jwtd mcp` options: `--transport [stdio|streamable-http]`, `--host` (loopback only),
366
+ `--port`, `--config FILE`. Over HTTP the server always enables DNS rebinding protection and
367
+ accepts only its own address and `localhost` on its own port as `Host` and `Origin`.
368
+
369
+ ## Configuration
370
+
371
+ `jwtd config init` writes a commented configuration file that only you can read (mode 600,
372
+ in a folder with mode 700): remove the `#` in front of a setting to change it. It never
373
+ replaces a file unless you add `--force`, and `--path FILE` writes elsewhere. `jwtd config
374
+ path` prints the user file location (`JWTSCOPE_CONFIG` overrides it) and `jwtd config show`
375
+ prints the effective configuration. Every key is optional; unknown keys are rejected.
376
+
377
+ ```yaml
378
+ output:
379
+ format: text # text | json
380
+ colour: auto # auto | always | never
381
+ timezone: utc # utc | local | +HH:MM | an IANA name such as Europe/London
382
+ summary: true # show the Summary section in text output
383
+ limits:
384
+ max_token_bytes: 65536
385
+ max_key_file_bytes: 1048576
386
+ max_fetch_bytes: 1048576 # largest discovery document or key set accepted
387
+ time_claims: [exp, nbf, iat, auth_time, updated_at, xms_tcdt]
388
+ verify:
389
+ leeway_seconds: 0
390
+ require_exp: true
391
+ enforce_minimum_key_length: true
392
+ allowed_algorithms:
393
+ [RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES256K, ES384, ES512, EdDSA, Ed25519, Ed448,
394
+ ML-DSA-44, ML-DSA-65, ML-DSA-87, HS256, HS384, HS512]
395
+ required_claims: [] # NAME, NAME=TEXT or NAME:=JSON, as --require-claim
396
+ jwe:
397
+ allowed_key_algorithms:
398
+ [RSA-OAEP, RSA-OAEP-256, RSA-OAEP-384, RSA-OAEP-512, ECDH-ES, ECDH-ES+A128KW, ECDH-ES+A192KW,
399
+ ECDH-ES+A256KW, A128KW, A192KW, A256KW, A128GCMKW, A192GCMKW, A256GCMKW, dir,
400
+ PBES2-HS256+A128KW, PBES2-HS384+A192KW, PBES2-HS512+A256KW]
401
+ allowed_content_algorithms: [A128GCM, A192GCM, A256GCM, A128CBC-HS256, A192CBC-HS384, A256CBC-HS512]
402
+ allow_rsa1_5_decrypt: true # accepted with a warning; never used to encrypt
403
+ encode:
404
+ default_algorithm: RS256
405
+ default_lifetime_seconds: 3600
406
+ default_key_algorithm: RSA-OAEP-256
407
+ default_content_algorithm: A256GCM
408
+ fetch: # keys from --oidc and --jwks-url, over HTTPS only
409
+ timeout_seconds: 10
410
+ retries: 3 # on connection errors, HTTP 429 and 5xx, with backoff
411
+ cache_ttl_seconds: 3600 # or the server's Cache-Control max-age, when shorter
412
+ max_stale_seconds: 86400 # use cached keys this old, with a warning, when the issuer is down
413
+ min_refresh_interval_seconds: 60 # an unknown kid refreshes the keys at most this often
414
+ mcp:
415
+ transport: stdio # stdio | streamable-http
416
+ host: 127.0.0.1
417
+ port: 8765
418
+ allow_clipboard: false
419
+ allow_network: false # let verify_jwt fetch keys (oidc_issuer, jwks_url)
420
+ allowed_key_urls: [] # URL prefixes it may fetch from, for example https://login.microsoftonline.com/
421
+ logging:
422
+ level: WARNING
423
+ claims: {} # extra claim labels, for example dept: Department
424
+ claim_values: {} # value descriptions, for example dept: {"4711": Finance}
425
+ profiles: [] # extra issuer profiles, tried before the packaged ones
426
+ ```
427
+
428
+ `jwtd completion bash|zsh|fish` prints a shell completion script for both command names.
429
+
430
+ ## Exit codes
431
+
432
+ | Code | Meaning |
433
+ |---|---|
434
+ | 0 | Success |
435
+ | 1 | Input is not a decodable token, or a `--get` value is missing |
436
+ | 2 | Usage error |
437
+ | 3 | Verification or decryption failed |
438
+ | 4 | Key, configuration or input source error, or keys could not be fetched |
439
+ | 5 | Token expired or not yet valid (`--require-active`) |
440
+ | 70 | Internal error; run again with `--debug` for details |
441
+ | 130 | Interrupted |
442
+ | 141 | Output closed early by the reader, for example `jwtd ... \| head -1` |
443
+
444
+ ## Coming from `jwt-cli`
445
+
446
+ | `jwt-cli` 6.2.0 | `jwtscope` |
447
+ |---|---|
448
+ | `jwt decode <t>` | `jwtd <t>` |
449
+ | `jwt decode -` | `jwtd -`, or a pipe |
450
+ | `--date` | Always on; choose the zone with `--tz` |
451
+ | `--secret @key.pem` | `jwtd verify --key key.pem` |
452
+ | `--secret <text>` | `--secret-env NAME` or `--secret-file FILE` |
453
+ | `--ignore-exp` | Unchanged on `verify` |
454
+ | `--out FILE` | Shell redirection |
455
+ | `jwt encode` | `jwtd encode` (secrets from the environment or a file, never the command line) |
456
+
457
+ The Rust implementation is kept at tag `rust-6.2.0` for reference only. It is unsupported
458
+ and its crates have published security advisories.
459
+
460
+ ## Development
461
+
462
+ ```bash
463
+ # Create the environment with every extra and the development tools
464
+ uv sync --all-extras
465
+ # Run the tests with the coverage gate
466
+ uv run pytest --cov=jwtscope --cov-fail-under=95
467
+ # Lint, check formatting and type check
468
+ uv run ruff check . && uv run ruff format --check . && uv run mypy --strict src
469
+ ```
470
+
471
+ Security issues: see [SECURITY.md](SECURITY.md). Licence: [MIT](LICENSE.md).