Skip to content

Latest commit

 

History

History
56 lines (45 loc) · 1.03 KB

README.md

File metadata and controls

56 lines (45 loc) · 1.03 KB

token

TXN2 JWT token middleware for gin-gonic.

gin-gonic Implementation

Includes:

import (
	"github.com/gin-gonic/gin"
	"github.com/txn2/token"
)

Add token middleware:

// gin router
r := gin.New()

// token middleware
jwt := token.NewJwt(token.JwtCfg{
    Exp:    10, // minutes
    EncKey: []byte("DZCAJZGByGb7pGc3zJKdQ9wGYKRDZpZETZN46tzTWFT"),
})

r.Use(jwt.GinHandler())

Example

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 $TOKEN

Validate the token:

curl http://localhost:8080/validate -H "Authorization: Bearer $TOKEN"