Skip to content

scanbadge/api

Repository files navigation

ScanBadge API

REST API for initiating, maintaining and authenticating ScanBadge, written in Go.

GoDoc

Setup

  1. $ 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.

Sample configuration

config.json

{
  "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"
  }
}

FAQ

Do you have a list of your API endpoints?

Yes, we have. Our API is RESTful, so endpoints support GET,PUT,POST,DELETE requests. The following endpoints are currently implemented:

  • /auth1
  • /actions
  • /conditions
  • /devices
  • /logs
  • /users

1 only used for authentication

See the API documentation for more detailed information about our endpoints.

How do I create the first API user?

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"}

Links

About

API for initiating, maintaining and authenticating ScanBadge

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages