auth-api/README.md

34 lines
1.9 KiB
Markdown
Raw Normal View History

2021-01-06 19:31:51 +01:00
# Auth API
This is a tiny http API for auth. Register accounts, auth with api-key or name/password, renew JWT tokens...
2020-12-29 13:46:58 +01:00
## Databaes migration
Done using [dbmate](https://github.com/amacneil/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/pwrpln?sslmode=disable" --network=host -v "$(pwd)/db:/db" amacneil/dbmate up`
Example of setting up a postgres SQL server:
2021-01-02 11:56:24 +01:00
`docker run -d --name postgres --network=host -e POSTGRES_PASSWORD=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=pwrlpln postgres`
2021-01-04 16:28:03 +01:00
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=pwrlpln postgres`
2021-01-02 11:56:24 +01:00
## 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.
2021-01-04 16:23:45 +01:00
## 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`
2021-01-04 16:47:06 +01:00
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`