Once we have a REST API endpoint and a JWT token generator handler in hand, we can easily secure our endpoints with the JWT, which we will be covering in this recipe.
Securing a RESTful service using a JSON web token
How to do it...
- Install the github.com/auth0/go-jwt-middleware, github.com/dgrijalva/jwt-go, github.com/gorilla/mux, and github.com/gorilla/handlers packages using the go get command, as follows:
$ go get github.com/auth0/go-jwt-middleware
$ go get github.com/dgrijalva/jwt-go
$ go get github.com/gorilla/handlers
$ go get github.com/gorilla/mux
- Create http-rest-api-secured.go, where we will define the JWT middleware to check for JWTs on HTTP requests, and wrap the /employees route with it, as follows:
package...