TXN2 JWT token middleware for gin-gonic.
Includes:
import (
"github.com/gin-gonic/gin""github.com/txn2/token"
)Add token middleware:
// gin routerr:=gin.New()
// token middlewarejwt:=token.NewJwt(token.JwtCfg{
Exp: 10, // minutesEncKey: []byte("DZCAJZGByGb7pGc3zJKdQ9wGYKRDZpZETZN46tzTWFT"),
})
r.Use(jwt.GinHandler())Run Source:
go run ./example/server.go --key="n2r5u8x/A?D(G+KbPdX"Tokenize a JSON object:
TOKEN=$(curl -X POST http://localhost:8080/tokenize?raw=true -d '{ "id": "sysop", "description": "Global system operator", "display_name": "System Operator", "active": true, "sysop": true, "password": "REDACTED", "sections_all": false, "sections": [], "accounts": [], "admin_accounts": []}')&&echo$TOKENValidate the token:
curl http://localhost:8080/validate -H "Authorization: Bearer $TOKEN"