REST API for initiating, maintaining and authenticating ScanBadge, written in Go.
$ go get -u github.com/scanbadge/api
$ go install github.com/scanbadge/api
- Create a new key for creating/verifying JWT, e.g.
$ openssl rand -out $GOPATH/bin/scanbadge.key -base64 256
- Add and edit the
config.json
to$GOPATH/bin/config.json
. - Use
$ cd $GOPATH/bin && ./api
to run ScanBadge API. - Gorp will automatically create empty tables in the selected database.
- Add the first API user.
{
"ServerHost": "localhost",
"ServerPort": 8080,
"Key": "scanbadge.key",
"Database": {
"Username": "username",
"Password": "password",
"DatabaseName": "scanbadge",
"Protocol": "tcp",
"Host": "localhost",
"Port": "3306",
"Charset": "utf8mb4,utf8",
"Engine": "InnoDB",
"Encoding": "UTF8"
}
}
Yes, we have. Our API is RESTful, so endpoints support GET
,PUT
,POST
,DELETE
requests. The following endpoints are currently implemented:
/auth
1/actions
/conditions
/devices
/logs
/users
1 only used for authentication
See the API documentation for more detailed information about our endpoints.
Run API with flag -add-user
, e.g. $ ./api -add-user
and follow the on-screen instructions.
If the user is successfully added, you can obtain an authentication token by sending a POST
request to /auth
using multipart/form-data
: username=foo&password=bar
or use cURL:
$ curl --form "username=foo" --form "password=bar" https://api.example.org/auth
If the authentication is successful, a JSON-encoded result with the authentication token will be returned, like so:
{"token":"eyJhbGciOiJIUzI1NiIsImtpZCI6ImxvZ2luIiwidHlwIjoiSldUIn0.eyJleHAiOjQyOTQ5NjcyOTUsImlkIjoxLCJuYW1lIjoiRm9vIEJhciJ9.5wPuGctuwTb0EqD_ER1dGQQeK2RyIGq64w552_zW-sw"}