diff --git a/README.md b/README.md index 400854f..3318fc8 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ all unverified tokens, see jwtauth.Authenticator. package myservice import ( - "github.com/dgrijalva/jwt-go" + "net/http" + "github.com/goware/jwtauth" "github.com/pressly/chi" "golang.org/x/net/context" @@ -42,37 +43,38 @@ import ( var TokenAuth *jwtauth.JwtAuth func init() { - TokenAuth = jwtauth.New("HS256", []byte("secret"), nil) + TokenAuth = jwtauth.New("HS256", []byte("secret"), nil) } func router() http.Handler { - r := chi.NewRouter() + r := chi.NewRouter() - // Protected routes - r.Group(func(r chi.Router) { - // Seek, verify and validate JWT tokens - r.Use(TokenAuth.Verifier) + // Protected routes + r.Group(func(r chi.Router) { + // Seek, verify and validate JWT tokens + r.Use(TokenAuth.Verifier) - // Handle valid / invalid tokens. In this example, we use - // the provided authenticator middleware, but you can write your - // own very easily, look at the Authenticator method in jwtauth.go - // and tweak it, its not scary. - r.Use(jwtauth.Authenticator) + // Handle valid / invalid tokens. In this example, we use + // the provided authenticator middleware, but you can write your + // own very easily, look at the Authenticator method in jwtauth.go + // and tweak it, its not scary. + r.Use(jwtauth.Authenticator) - r.Get("/admin", func(ctx context.Context, w http.ResponseWriter, r *http.Request) { - w.Write([]byte("protected")) - }) - }) + r.Get("/admin", func(ctx context.Context, w http.ResponseWriter, r *http.Request) { + w.Write([]byte("protected")) + }) + }) - // Public routes - r.Group(func(r chi.Router) { - r.Get("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) { - w.Write([]byte("welcome")) - }) - }) + // Public routes + r.Group(func(r chi.Router) { + r.Get("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) { + w.Write([]byte("welcome")) + }) + }) - return r + return r } + ``` # LICENSE