Skip to content

API: Authentication

Log in with Basic username/password credentials, then send the returned access token as Authorization: Bearer {ACCESS_TOKEN} on authenticated API requests.

Use the v2 login, refresh, and logout endpoints to manage renewable sessions. Both login versions require Basic credentials; a Bearer token cannot be used in place of them.

Login (v2)

Each successful login creates an independent refresh session.

POST /api/v2/auth/login HTTP/1.1
Authorization: Basic {Base64(username:password)}

The JSON response contains:

Field Meaning
accessToken JWT used for authenticated API requests
refreshToken Opaque token used to renew this session
tokenType Always Bearer
expiresIn Access-token lifetime in seconds
refreshExpiresAt Fixed refresh-session expiry as a date-time

For example, curl --user prompts for the password when only a username is supplied:

curl --user username --request POST https://local-c2:8443/api/v2/auth/login

Store both tokens securely. Login and refresh responses must not be cached. Use the server's certificate authority with --cacert when it is not already trusted.

Refresh (v2)

Send the current refresh token in the JSON body. This endpoint does not require an Authorization header.

1
2
3
4
5
6
POST /api/v2/auth/refresh HTTP/1.1
Content-Type: application/json

{
  "refreshToken": "{REFRESH_TOKEN}"
}

A successful response has the same fields as login and replaces both tokens. The previous refresh token becomes unusable. Reusing it revokes the entire refresh session, so serialize refresh requests and replace the stored token pair together. Rotation does not extend refreshExpiresAt.

A missing or blank token returns 400. An invalid, expired, or revoked token returns 401; log in again with Basic credentials.

Logout (v2)

Logout revokes the refresh session identified by any of its refresh tokens.

1
2
3
4
5
6
POST /api/v2/auth/logout HTTP/1.1
Content-Type: application/json

{
  "refreshToken": "{REFRESH_TOKEN}"
}

The endpoint returns 204, including for unknown or already revoked tokens. A missing or blank token returns 400. Existing access JWTs remain valid until their expiry; logout prevents further renewal of this session.

Login (v1 compatibility)

The v1 login endpoint is deprecated but remains available with Basic credentials. Its response is a JWT string, rather than the v2 token object.

POST /api/v1/auth/login HTTP/1.1
Authorization: Basic {Base64(username:password)}
eyJhbGciOiJSUzI1NiJ9...

Pass that string as Authorization: Bearer {JWT_TOKEN} on subsequent requests. Use v2 when an integration needs renewable sessions.

Token lifetimes

The v2 access token lasts 900 seconds (15 minutes) by default. Its refresh session lasts 604800 seconds (7 days), measured from the initial login; refresh rotation does not extend that deadline. Server administrators can set tuoni.auth.tokens.access-expiry-seconds and tuoni.auth.tokens.refresh-expiry-seconds to positive values.

The separate tuoni.auth.jwt.expiry-seconds setting controls JWTs returned by the legacy v1 login endpoint. It does not change v2 access or refresh lifetimes.

WebSocket authentication and browser origins

WebSocket connections enforce access-token expiry and current permissions. Custom clients must obtain a valid access token and reconnect when their connection's token expires. Refreshing a REST token does not renew an existing WebSocket connection.

Browser connections use same-origin checks by default. If the browser client is served from a different origin, configure its exact scheme, hostname, and port:

1
2
3
4
tuoni:
  websocket:
    allowed-origins:
      - https://client.example.test:12702

Use the origin seen by the browser, including any nondefault port. Wildcard origins are not supported. See Setting Up the C2 for deployment configuration. For the endpoint, subscriptions, permissions, and message shapes, see WebSocket events.