Jwt is a web json service middleware for tango
Go to file
Lunny Xiao e76f781634 Merge pull request #2 from insionng/patch-1
Update README.md
2015-09-18 08:13:45 +06:00
jwt_test.go test bug fixed 2015-08-23 22:59:46 +08:00
jwt.go Update jwt.go 2015-08-23 23:56:42 +08:00
LICENSE init 2015-08-22 22:58:56 +08:00
README.md Update README.md 2015-09-18 10:03:52 +08:00

jwt middleware for tango

Development

Use example:

import (
    "net/http"

    "github.com/lunny/tango"
    "github.com/tango-contrib/jwt"
)

var (
    key = "mykey"
)

type JwtAction struct {
    jwt.Auther
}

func (j *JwtAction) Get() string {
    return j.GetClaim("username")
}

func main() {
    tg := tango.Classic()
    tg.Use(jwt.New(jwt.Options{
        KeyFunc: func(ctx *tango.Context) (string, error) {
            return key, nil
        },
    }))
    tg.Any("/jwt", new(JwtAction))

    go tg.Run()

    token, err := jwt.NewToken(key, map[string]interface{}{
            "username": name,
        })

    req, err := http.NewRequst("GET","http://localhost:8000/jwt", nil)
    req.Header.Add("Authorization", "Bearer "+token)

    http.Do(req)
}