golang-jwt
A Go implementation of JSON Web Tokens for signing, parsing, and validating JWT tokens.
Official Documentation ↗v5.2. Check the official docs for the latest API surface.Installation
go get github.com/golang-jwt/jwt/v5Methods
No methods match this filter.
golang-jwt creates signed tokens with claims and verifies them using a key function.
Key Features
- Standard and custom claims
- HMAC, RSA, and ECDSA signing
- Key function validation hooks
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://pkg.go.dev/github.com/golang-jwt/jwt/v5 · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:58.777Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- New ("key is not a valid ECDSA public key") ErrNotECPrivateKey = errors . (https://pkg.go.dev/github.com/golang-jwt/jwt/v5)
- New ("key is not a valid ECDSA private key") ) View Source var ( ErrNotEdPrivateKey = errors . (https://pkg.go.dev/github.com/golang-jwt/jwt/v5)
- New ("key is not a valid Ed25519 private key") ErrNotEdPublicKey = errors . (https://pkg.go.dev/github.com/golang-jwt/jwt/v5)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://pkg.go.dev/github.com/golang-jwt/jwt/v5 · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:58.777Z.
- SECURITY NOTICE: Some older versions of Go have a security issue in the crypto/elliptic. (https://pkg.go.dev/github.com/golang-jwt/jwt/v5)
- SECURITY NOTICE: It’s important that you validate the alg presented is what you expect . (https://pkg.go.dev/github.com/golang-jwt/jwt/v5)
- We no longer support building jwt-go with unsupported Go versions, as these contain security vulnerabilities that will not be fixed. (https://pkg.go.dev/github.com/golang-jwt/jwt/v5)
FAQ
- How do I restrict the signing algorithm?
- Pass jwt.WithValidMethods(["HS256"]) to the parser so tokens using other algorithms are rejected.
- Are exp and nbf validated?
- Yes. Registered claims like exp, nbf, and iat are checked during parse when present.
- How should I store the key?
- Load it from configuration or a secret manager; never hardcode it, and rotate it periodically.
Report a problem with this API docOpens a pre-filled issue on GitHub.