Jwt

Safe, simple and fast JSON Web Tokens for Go
Alternatives To Jwt
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Jwt6,9106,8175354 days ago51August 19, 20225bsd-3-clausePHP
A simple library to work with JSON Web Token and JSON Web Signature
Pyjwt4,5189,4431,6062 days ago45May 12, 202222mitPython
JSON Web Token implementation in Python
Jsmn3,090
5 months ago88mitC
Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
Jwt1,94431330519 days ago122September 26, 20227otherC#
Jwt.Net, a JWT (JSON Web Token) implementation for .NET
Node Jwt Simple1,3207,8285692 years ago13March 30, 201933mitJavaScript
JWT(JSON Web Token) encode and decode module for node.js
Vault Ui1,299
5 years ago3October 04, 201750otherJavaScript
Vault-UI — A beautiful UI to manage your Vault, written in React
Frangipanni1,156
3 months ago6April 10, 20216mitGo
Program to convert lines of text into a tree structure.
Spring Boot Jwt1,022
a year agomitJava
JWT auth service using Spring Boot, Spring Security and MySQL
Token Lists942516 days ago30June 16, 202291mitTypeScript
📚 The Token Lists specification
Jwt844
6 years agomitJava
webapp用户身份认证方案 JSON WEB TOKEN 实现Deme示例,Java版
Alternatives To Jwt
Select To Compare


Alternative Project Comparisons
Readme

jwt

build-img pkg-img reportcard-img coverage-img version-img

JSON Web Token for Go RFC 7519, also see jwt.io for more.

The latest version is v5.

Rationale

There are many JWT libraries, but many of them are hard to use (unclear or fixed API), not optimal (unneeded allocations + strange API). This library addresses all these issues. It's simple to read, to use, memory and CPU conservative.

Features

  • Simple API.
  • Clean and tested code.
  • Optimized for speed.
  • Concurrent-safe.
  • Dependency-free.
  • All well-known algorithms are supported
    • HMAC (HS)
    • RSA (RS)
    • RSA-PSS (PS)
    • ECDSA (ES)
    • EdDSA (EdDSA)
    • or your own!

See GUIDE.md for more details.

Install

Go version 1.17+

go get github.com/cristalhq/jwt/v5

Example

Build new token:

// create a Signer (HMAC in this example)
key := []byte(`secret`)
signer, err := jwt.NewSignerHS(jwt.HS256, key)
checkErr(err)

// create claims (you can create your own, see: Example_BuildUserClaims)
claims := &jwt.RegisteredClaims{
    Audience: []string{"admin"},
    ID:       "random-unique-string",
}

// create a Builder
builder := jwt.NewBuilder(signer)

// and build a Token
token, err := builder.Build(claims)
checkErr(err)

// here is token as a string
var _ string = token.String()

Parse and verify token:

// create a Verifier (HMAC in this example)
key := []byte(`secret`)
verifier, err := jwt.NewVerifierHS(jwt.HS256, key)
checkErr(err)

// parse and verify a token
tokenBytes := token.Bytes()
newToken, err := jwt.Parse(tokenBytes, verifier)
checkErr(err)

// or just verify it's signature
err = verifier.Verify(newToken)
checkErr(err)

// get Registered claims
var newClaims jwt.RegisteredClaims
errClaims := json.Unmarshal(newToken.Claims(), &newClaims)
checkErr(errClaims)

// or parse only claims
errParseClaims := jwt.ParseClaims(tokenBytes, verifier, &newClaims)
checkErr(errParseClaims)

// verify claims as you wish
var _ bool = newClaims.IsForAudience("admin")
var _ bool = newClaims.IsValidAt(time.Now())

Also see examples: example_test.go.

Documentation

See these docs.

License

MIT License.

Popular Token Projects
Popular Json Projects
Popular Security Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Go
Golang
Json
Token
Jwt
Rsa
Golang Library
Jwt Token
Jose
Jws
Jwe