/auth-jwt-server-task

🔑 Simple jwt go server (test task)

Primary LanguageGo

Go + JWT + Mongo

An example JWT auth server in Go with MongoDB.

Config

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

Run

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 username root; root password example
  • mongo-express (web ui for mongo) - port 8081 Disabled
  • JWT (from Dockerfile) server - port 1234

Libraries used

And...

Notes

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