https://github.com/nasermirzaei89/jwt
JSON Web Token library
https://github.com/nasermirzaei89/jwt
auth authentication authorization golang json-web-token jwt token
Last synced: 26 days ago
JSON representation
JSON Web Token library
- Host: GitHub
- URL: https://github.com/nasermirzaei89/jwt
- Owner: nasermirzaei89
- License: mit
- Created: 2019-08-19T07:19:47.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-31T23:07:05.000Z (over 4 years ago)
- Last Synced: 2025-11-21T16:02:57.687Z (7 months ago)
- Topics: auth, authentication, authorization, golang, json-web-token, jwt, token
- Language: Go
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JWT
JSON Web Token library

[](https://goreportcard.com/report/github.com/nasermirzaei89/jwt)
[](https://codecov.io/gh/nasermirzaei89/jwt)
[](https://pkg.go.dev/github.com/nasermirzaei89/jwt)
[](https://raw.githubusercontent.com/nasermirzaei89/jwt/master/LICENSE)
## Supported Algorithms
* [x] HS256
* [x] HS384
* [x] HS512
* [x] RS256
* [x] RS384
* [x] RS512
* [ ] ES256
* [ ] ES384
* [ ] ES512
* [ ] PS256
* [ ] PS384
* [ ] PS512
## Usage
### Sign
```go
package main
import (
"fmt"
"log"
"github.com/nasermirzaei89/jwt"
)
func main() {
token := jwt.New(jwt.HS256)
tokenStr, err := jwt.Sign(*token, []byte("secret_key"))
if err != nil {
log.Fatalln(err)
}
fmt.Println(tokenStr) // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.HUfJqC1q8JUPKD4jj8PZAYppSrQRL8tJHTljdcTfFCQ
}
```
### Verify
```go
package main
import (
"log"
"github.com/nasermirzaei89/jwt"
)
func main() {
tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.HUfJqC1q8JUPKD4jj8PZAYppSrQRL8tJHTljdcTfFCQ"
err := jwt.Verify(tokenStr, []byte("secret_key"))
if err != nil {
log.Fatalln(err)
}
}
```
### Sign With Claims
```go
package main
import (
"fmt"
"log"
"time"
"github.com/nasermirzaei89/jwt"
)
func main() {
token := jwt.New(jwt.HS256)
token.SetIssuer("https://yourdomain.tld")
token.SetExpirationTime(time.Now())
tokenStr, err := jwt.Sign(*token, []byte("secret_key"))
if err != nil {
log.Fatalln(err)
}
fmt.Println(tokenStr) // variable
}
```