Authentication

Overview

To use any authenticated API, you must first acquire a valid API token.

Crisisworks uses OAuth2 time-limited access tokens, and offers an auth endpoint to fetch the tokens. MFA is supported using TOTP codes.

Crisisworks account & Duty Status

API users must be approved by both Datalink and the Customer of the tenancy, and agree to the API Terms Of Use. If you do not see the API User position, contact Datalink Support to organise these approvals.

API users use the same security system as regular users.

It is recommended your API-enabled user account is only used for the API, as such give it a name like API User.

  • At minimum, this user will require the API User position allocated to it. If you cannot find this position, contact Datalink support.

  • Ensure this user also has the levels of access required to access the data it needs to view or edit for the specific registers.

  • If this API user is going to edit data in registers, the API user MUST BE ON DUTY in the event in one or more positions to have access to read or write data in the registers.

  • If the API user is only updating assets or asset contacts, this data is not in a register, so they don't need to be on duty in any events.

Fetching an authentication token

To fetch an authentication token, call the auth API command and supply the user credentials. Then supply that token to all authenticated API commands using the Authorization header to perform the command on behalf of that user.

Authentication tokens are OAuth2 JWT Access Tokens which expire after a short period. Therefore, for recurring use of the API you should store the username and password securely at your side and call the auth endpoint to fetch a new token.

The API also supports optional TOTP MFA, and you can supply mfaCode at the same time as supplying the username and password. The POSIX authtool utility can be used for this.

To call the auth API, use the following:

Parameter
Type
Mandatory
Description

uuid

string

Yes

A unique code that represents the connected device. For devices this is the device's UUID code. For servers, this should be the server's URL.

platform

string

Yes

A freetext string representing the type of connection — e.g. iPad, iPhone, Windows, Linux

version

string

Yes

The version of the client software — e.g. 11

name

string

Yes

The name of the device or integration — e.g. "Integration X"

username

string

Yes

The user username

password

string

Yes

The user's password

mfaCode

string

No

An optional TOTP MFA code

If the user is successfully authenticated, the command returns a JSON object with the following values:

Key
Type
Description

token

string

An OAuth2 Access Token which can be used to perform actions on behalf of a nominated user

status

int

200 for success, 400 for invalid intput, 401 for invalid credentials, 500 for internal server errors

type

string

The type of token returned (this will always be 'accessToken')

If the user's credentials are invalid, the server responds with a 401 HTTP error.

The access token will have a 1 hour expiry, so you will need to re-authenticate for each session.

Using oauthtool for CLI-based MFA

The oauthtool utility is open source software that can be downloaded using your package manager.

  • Debian/Ubuntu: sudo apt install oathtool

  • MacOS: brew install oath-toolkit

  • Windows (WSL or Chocolatey): choco install oath-toolkit

To generate TOTP codes using oathtool, you need the TOTP secret key from Crisisworks. Which can be found by clicking the link "Get code for manual entry" under the QR code when registering the TOTP device.

Next, register the TOTP by entering the following command with your TOTP secret.

Each time this is run, this command will return a six-digit TOTP code. You can run it once and enter into Crisisworks to register the tool with Crisisworks for MFA.

Using an authentication token

Once you have acquired the auth token, you can use it for all APIs via the Authorization header as follows.

Both Authorization and X-Site are required for most API calls.

Treat your secrets securely

The examples in this guide take shortcuts for readability, with the main one being the storage of secrets in environment variables.

For production use:

  • API users typically have high degrees of access.

  • Treat your API user's password and TOTP secret as sensitive secrets.

  • Don’t hardcode secrets in scripts — use environment variables or secure vault utilities.

For secure storage options, consider using these utilities such as these.

Examples

Authenticating in BASH

The following simple example shows how to call the auth command from a bash script.

Authenticating with MFA in BASH

The following shell script illustrates how to authenticate with MFA in bash and curl.

Now you can call the authenticated commands using the token.

Authenticating with MFA in PowerShell

The following example shows how to authenticate in Windows PowerShell.

Now you can call the other API commands using the token.

Authenticating in PHP

The above code uses a function to perform the HTTP call

Last updated

Was this helpful?