Go to file
2021-06-24 01:59:44 +02:00
db Protected POST /account and fixed with JWT stuff in general 2021-01-03 18:21:42 +01:00
src Added PUT /account/{id}/fields 2021-06-24 01:55:47 +02:00
tests Added PUT /account/{id}/fields 2021-06-24 01:55:47 +02:00
.dockerignore Removed stuff that should not be there 2021-06-23 22:31:31 +02:00
.env_example doc tweaks 2021-01-06 19:35:03 +01:00
.gitignore Some kind of starting point 2020-12-29 13:46:58 +01:00
docker-compose.yml More tests and DELETE account 2021-06-24 00:42:54 +02:00
Dockerfile Loads of updates 2021-06-22 22:52:48 +02:00
go.mod Loads of updates 2021-06-22 22:52:48 +02:00
go.sum Loads of updates 2021-06-22 22:52:48 +02:00
README.md Updated README 2021-06-24 01:59:44 +02:00

Auth API

This is a tiny http API for auth. Register accounts, auth with api-key or name/password, renew JWT tokens...

Quick start with docker compose

Migrate database: docker-compose run --rm db-migrations

Run tests: docker-compose run --rm tests

Start the service (on port 4000 by default): docker-compose up -d (db migrations must be ran before this)

Databaes migration

Done using dbmate. Db stuff is stored in ./db.

Example of running the migrations:

docker run --rm -it -e DATABASE_URL="postgres://postgres:postgres@127.0.0.1:5432/auth?sslmode=disable" --network=host -v "$(pwd)/db:/db" amacneil/dbmate up

Example of setting up a postgres SQL server:

docker run -d --name postgres --network=host -e POSTGRES_PASSWORD=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=auth postgres

If you are on of those poor people runnin macOS you must use this one to start a postgres server :(

docker run -d --name pwrpln-postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=auth postgres

Admin account

On first startup with a clean database, an account with name "admin" and the field "role" with a value "admin" is created with no password, using the API Key from ADMIN_API_KEY in the .env file.

Special account field: "role"

The account field "role" is a bit special, in that if it contains "admin" as one of its values, that grants access to all methods on all accounts on this service. It might be a good idea to use the field "role" for authorization throughout your services.

Some useful cURLs

Obtain an admin GWT: curl -d '"api-key-goes-here"' -H "Content-Type: application/json" -i http://localhost:4000/auth/api-key

Use a bearer token to make a call: curl -H "Content-Type: application/json" -H "Authorization: bearer your-JWT-token-goes-here" -i http://localhost:4000/account/{accountID}

Create account: curl -d '{"name": "Bosse", "password":"Hemligt", "fields": [{ "name":"role", "values":["user"]}]}' -H "Content-Type: application/json" -H "Authorization: bearer your-JWT-token-goes-here" -i http://localhost:4000/account