Go to file
Lilleman 1859f8d7bc
Some checks failed
continuous-integration/drone/push Build is failing
Updated all go modules
2022-02-27 17:34:42 +01:00
db Protected POST /account and fixed with JWT stuff in general 2021-01-03 18:21:42 +01:00
src Fixed internal server error for trying to login with wrong username 2022-02-27 17:32:30 +01:00
tests Fixed internal server error for trying to login with wrong username 2022-02-27 17:32:30 +01:00
.dockerignore Minor stuff 2022-01-22 15:35:58 +01:00
.drone.yml Fixed error in docker tagging 2022-02-15 20:17:25 +01:00
.env_example Fixed internal server error for trying to login with wrong username 2022-02-27 17:32:30 +01:00
.gitignore Latest udpates 2021-12-10 23:09:57 +01:00
docker-compose.yml Fixed internal server error for trying to login with wrong username 2022-02-27 17:32:30 +01:00
Dockerfile Playing with pipelines 2022-02-15 19:24:22 +01:00
Dockerfile.migrations Updated tag pipeline 2022-02-15 19:53:21 +01:00
go.mod Updated all go modules 2022-02-27 17:34:42 +01:00
go.sum Updated all go modules 2022-02-27 17:34:42 +01:00
LICENSE Added license and upgraded postgres 2022-02-18 19:27:02 +01:00
README.md Remvoed test code 2022-02-14 00:17:08 +01:00

Auth API

A tiny REST 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

Start the API (on port 4000 by default): docker-compose up -d

Point your browser to http://localhost:4000 to view the swagger API documentation.

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.

Tests

Run integration tests (Requires migrated database and started API): docker-compose run --rm tests

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