JWT

Zero-dependency, lightweight and fast JWT and JWKS implementation written in Go. It was designed with security, performance and simplicity in mind, and it protects your tokens from critical vulnerabilities found in other libraries.

Please star this open source project to attract more developers so that together we can improve it even more!
Ask AI about jwt. Google's free Code Wiki for jwt is generated from this repository and stays in sync with it, commit by commit. Browse the architecture with diagrams, or ask its chat plain-language questions about the codebase and get answers grounded in the actual source. For an assistant that writes jwt code with you, Plexon AI, the desktop assistant built by the author of jwt, ships the jwt skill built in; see AI Tools for jwt below.
The Book
A fourteen chapter book on this library lives in book/, rendered to one
self-contained HTML file and printed to PDF.
It is not a reference. go doc is the reference, and it is generated from the source so it
cannot drift. The book is the part go doc cannot give you: the order to do things in, why
a default is what it is, and the failure that made somebody choose it. Chapter 12 is the
honest list of this library's sharp edges.
Read the PDF (121 pages), or start with the
preface and read the chapters as Markdown:
| Chapter | What it covers |
|---|
| Preface | Who the book is for, and how its code was checked |
| 1 | What a Token Is | The three segments, base64url, and what a signature actually proves |
| 2 | Signing and Verifying | Sign and Verify, and why the algorithm is an argument |
| 3 | Claims | Standard and custom claims, sign options, Merge |
| 4 | Expiry and Time | exp, nbf, iat, MaxAge, and clock skew |
| 5 | Choosing an Algorithm | HMAC, RSA, RSA-PSS, ECDSA, EdDSA, and who can mint tokens |
| 6 | Keys and Rotation | The kid registry, key configuration, and a worked rotation |
| 7 | JWKS | Publishing a key set, consuming one, and KeySet |
| 8 | Validators | The chaining rule, Expected, and writing your own |
| 9 | Revoking Tokens | Blocklists, jti, and a distributed backend |
| 10 | Tokens over HTTP | Extraction, middleware, and access and refresh pairs |
| 11 | Encrypting the Payload | AES-GCM, and when the answer is not encryption |
| 12 | Sharp Edges | The surprising defaults and the fast paths that carry a hazard |
| 13 | Testing | Controlling the clock, faking the network, golden tests |
| 14 | Performance | Where the time goes, and what buys the speed |
| Epilogue | The pattern behind most of the defects found here |
Rebuild it with cd book && go run ., or go run . -format html for a version that needs
no browser. See book/README_EBOOK.md.
Installation
The only requirement is Go 1.27 or newer.
$ go get github.com/kataras/jwt@latest
Import as import "github.com/kataras/jwt" and use it as jwt.XXX.
Table of Contents