From 7b878235a192e78880a3b1e878bde9c7c1384bcb Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Fri, 22 Jan 2016 13:45:28 -0500 Subject: [PATCH] Show how to get token from context --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3318fc8..2e315fb 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,10 @@ all unverified tokens, see jwtauth.Authenticator. package myservice import ( + "fmt" "net/http" + "github.com/dgrijalva/jwt-go" "github.com/goware/jwtauth" "github.com/pressly/chi" "golang.org/x/net/context" @@ -61,7 +63,9 @@ func router() http.Handler { r.Use(jwtauth.Authenticator) r.Get("/admin", func(ctx context.Context, w http.ResponseWriter, r *http.Request) { - w.Write([]byte("protected")) + token := ctx.Value("jwt").(*jwt.Token) + claims := token.Claims + w.Write([]byte(fmt.Printf("protected area. hi %v", claims["user_id"]))) }) }) @@ -74,7 +78,6 @@ func router() http.Handler { return r } - ``` # LICENSE