https://github.com/mdigger/jwt
JSON Web Token
https://github.com/mdigger/jwt
jwkset jwt jwt-auth jwt-token
Last synced: 5 months ago
JSON representation
JSON Web Token
- Host: GitHub
- URL: https://github.com/mdigger/jwt
- Owner: mdigger
- License: mit
- Created: 2016-01-06T07:13:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-06-20T06:28:18.000Z (about 5 years ago)
- Last Synced: 2024-06-20T15:52:58.508Z (about 2 years ago)
- Topics: jwkset, jwt, jwt-auth, jwt-token
- Language: Go
- Homepage:
- Size: 62.5 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Web Token
[](https://pkg.go.dev/github.com/mdigger/jwt)
```golang
import "github.com/mdigger/jwt"
// create a pattern and describe in it the things that we would like to
// include all the tokens
conf := jwt.Config{
Issuer: "me.mdigger.test",
Expires: time.Hour,
Created: true,
Key: `top secret`,
}
// describe additional fields of token (structure)
data := jwt.JSON{
"sub": "34529345",
"email": "dmitrys@example.com",
"name": "Dmitry Sedykh",
"birthday": jwt.Time{time.Date(1971, time.December, 24, 0, 0, 0, 0, time.Local)},
}
// create and sign the token
token, err := conf.Token(data)
if err != nil {
log.Fatalln("Error creating:", err)
}
// ---------------------------------------------------
// parse a token and get data
// if the token is not valid, then return an error
claim := make(jwt.JSON)
if err := jwt.Decode(token, &claim); err != nil {
log.Fatalln("Error parsing:", err)
}
```