jwt-go is a microservice that provides API for creating JWT Token and verifing the JWT token.
-
Go 1.12 or higher
-
Do NOT disable Go modules (
export GO111MODULE=on
)
- release_mode - this will enable and disable the debug mode. default is false.
- log_level - logging level, it can be DEBUG,INFO,WARN,ERROR,OFF
- [app] name - name of the application
- [app] version - version of the application
- [server] graceful - graceful shutdown
- [server] addr - socket address
- [server] domain_api - serving domain
- [jwt] jwt_secret_key - secret key to be used for generate and verify jwt token
- [jwt] expire_minutes - expire duration of jwt token
[app]
name = "jwt-go"
version = "0.0.1"
[server]
graceful = true
addr = ":8090"
domain_api = "localhost"
[jwt]
jwt_secret_key = "my_secret_key"
expire_minutes = 10
There are 2 methods explained in this document to install jwt-go:
- Manual Installation Steps
- Docker Based Installation
Please do only one method, do not do both methods, unless of course you know what you're doing.
-
Clone the jwt-go into your go path and change directory to cloned repository.
git clone https://@github.com/tiniyo/jwt-go.git cd jwt-go
-
Build the jwt-go microservice
go build -o jwt-go main.go
-
Set the configuration as per your requirement
vim config/config.toml
-
Now you are ready the run the jwt-go microservice
./jwt-go
-
Clone the jwt-go into your go path and change directory to cloned repository.
git clone https://@github.com/tiniyo/jwt-go.git cd jwt-go
-
Build the jwt-go microservice
docker build -t jwt-go .
-
Now you are ready the run the jwt-go microservice
docker run jwt-go
jwt-go microservice provides 2 API's for creating and verifying the jwt token:
-
Request
POST http://yourdomain:8090//jwt { "name": "Test", "admin": true }
Success Response
{ "token": "your_new_generated_token" }
-
Request
GET http://yourdomain:8090//jwt --header Authorization: Bearer your_jwt_token
Success Response
{ "name": "Test", "admin": true }
Failed Response
{ "message": "invalid or expired jwt" }