An example JWT auth server in Go with MongoDB.
The server is configured via environment variables and with .env
file.
Predefined env variables has more priority than those from .env
file (consider it as a sensible defaults).
Refer to template.env
for more.
# Use this template like this
cp template.env .env
docker-compose.yml
contains sensible env variables (such as SERVER_JWT_SECRET
) just for demonstration purposes. You can run it without configuring anything.
docker compose up
It will spin up a...
- mongo - port
27017
; root usernameroot
; root passwordexample
- mongo-express (web ui for mongo) - port
8081
Disabled - JWT (from Dockerfile) server - port
1234
- koanf - for configuration management
- echo - web framework
- mongo-go-driver - mongodb driver
- jwt-go
And...
- oapi-codegen - generates server boilerplate from openapi schema.
The task requires hashing refresh tokens in DB with bcrypt
but it can't operate
on passwords longer that 72 bytes which makes it unsuitable for JWT tokens, so
I used sha512
for that purpose
https://stackoverflow.com/questions/64860460/store-the-hashed-jwt-token-in-the-database