Boiler plate code for APIs protected by username/login and javascript web token with a 10 minute expiry time.
Companion app, which provides the UI for this API server
Features
- New users get saved to Postgres.
- Set Env Var
NEEDS_AUTH=yes
on Heroku for auth - If you want auth also set
TOKEN_PASSWORD=yourlongsecretkeyhere
so you can generate tokens
Endpoints:
- api/user/login
- api/user/new
- api/quote
The login
and new
take a JSON payload of {"email": "valar@morghulis.com", "password": "valardohaeris"}
While quote
requires an Authorisation Header with the Bearer token issued by user creation or log in (if NEEDS_AUTH == yes)
This repo is heavily based on Adigun Olalekan's excellent post here: https://medium.com/@adigunhammedolalekan/build-and-deploy-a-secure-rest-api-with-go-postgresql-jwt-and-gorm-6fadf3da505b
again...