Skip to content
This repository has been archived by the owner on Mar 21, 2019. It is now read-only.

Latest commit

 

History

History
48 lines (36 loc) · 817 Bytes

README.md

File metadata and controls

48 lines (36 loc) · 817 Bytes

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)
}