A JWT plugin for gin, iris, go-frame, beego, go-zero, go-chassis, go-kit and other frameworks
Download and install
go get github.com/dobyte/jwt
Demo
package main
import (
"fmt"
"log"
"github.com/dobyte/jwt"
)
func main() {
auth := jwt.NewJWT(
jwt.WithIssuer("backend"),
jwt.WithSignAlgorithm(jwt.HS256),
jwt.WithSecretKey("secret"),
jwt.WithValidDuration(3600),
jwt.WithLookupLocations("header:Authorization"),
jwt.WithIdentityKey("uid"),
)
token, err := auth.GenerateToken(jwt.Payload{
"uid": 1,
"account": "fuxiao",
})
if err != nil {
log.Fatal("Generate token failed:" + err.Error())
}
fmt.Println(token)
}
View demo example/server.go
View demo example/jwt.postman.json