Skip to content

txn2/token

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"