https://github.com/metafates/auth-jwt-server-task
🔑 Simple jwt go server (test task)
https://github.com/metafates/auth-jwt-server-task
Last synced: 6 months ago
JSON representation
🔑 Simple jwt go server (test task)
- Host: GitHub
- URL: https://github.com/metafates/auth-jwt-server-task
- Owner: metafates
- Created: 2023-08-14T23:00:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-15T12:34:29.000Z (over 2 years ago)
- Last Synced: 2023-08-15T14:10:47.322Z (over 2 years ago)
- Language: Go
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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`](./template.env) for more.
```bash
# 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.
```bash
docker compose up
```
**It will spin up a...**
- [mongo](https://hub.docker.com/_/mongo) - port `27017`; root username `root`; root password `example`
- [mongo-express](https://hub.docker.com/_/mongo-express) (web ui for mongo) - port `8081` **Disabled**
- JWT (from [Dockerfile](./Dockerfile)) server - port `1234`
## Libraries used
- [koanf](https://github.com/knadh/koanf) - for configuration management
- [echo](https://github.com/labstack/echo) - web framework
- [mongo-go-driver](https://github.com/mongodb/mongo-go-driver) - mongodb driver
- [jwt-go](https://github.com/golang-jwt/jwt)
And...
- [oapi-codegen](https://github.com/deepmap/oapi-codegen) - generates server boilerplate from [openapi schema](./openapi.yaml).
## 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