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

tango-contrib/jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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