Creating a JSON web token

To secure your REST API or a service endpoint, you have to write a handler in Go that generates a JSON web token, or JWT.

In this recipe, we will be using https://github.com/dgrijalva/jwt-go to generate JWT , although you can implement any library from a number of third-party libraries available in Go, such as https://github.com/square/go-jose and https://github.com/tarent/loginsrv.

Get Go Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.