Refactor jwtauth pkg, move to go-chi org, and support dgrijalva/jwt-go v3

This commit is contained in:
Peter Kieltyka 2017-07-05 17:05:27 -04:00
parent d5f87ca5c3
commit 4c654d77d5
20 changed files with 180 additions and 1350 deletions

View file

@ -62,9 +62,8 @@ import (
"fmt"
"net/http"
"github.com/dgrijalva/jwt-go"
"github.com/goware/jwtauth"
"github.com/pressly/chi"
"github.com/go-chi/chi"
"github.com/go-chi/jwtauth"
)
var TokenAuth *jwtauth.JwtAuth
@ -99,9 +98,7 @@ func router() http.Handler {
r.Use(jwtauth.Authenticator)
r.Get("/admin", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
token := ctx.Value("jwt").(*jwt.Token)
claims := token.Claims
_, claims, _ := jwtauth.TokenContext(r.Context())
w.Write([]byte(fmt.Sprintf("protected area. hi %v", claims["user_id"])))
})
})