This repository exhibits the basic concept of middleware, in the context of Go-based HTTP Server.
This also holds utilities on dealing with JWT.
It generates RSA keypair (private.pem and public.pem).
go run cmd/rsagen/main.go
It generates a JWT (token.jwt) file, that can be generated using symmetric (HS256) or assymmetric (RS256) key.
See: https://auth0.com/blog/rs256-vs-hs256-whats-the-difference/.
To run with symmetric key, you need to specify the key.
go run cmd/jwtgen/main.go --symmetric --key supersecret
However, this program is by default generating RS256 token.
Note
Please make sure to generate RSA keypair first.
go run cmd/jwtgen/main.go
It validates the generated token.jwt using the defined key strategy (symmetric/asymmetric).
go run cmd/jwtgen/main.go --symmetric --key supersecret
And if the token.jwt was generated using RSHA256.
go run cmd/jwtgen/main.go