# Sign-in and profile API

> POST /api/auth/login, GET /api/auth/me and POST /api/auth/logout - the request, the answers, the session cookie and token, and what permissions null with permissions_error means.

Product: eaxScada · Type: Reference · Editions: Starter, Pro, Enterprise
Source: https://eaxware.com/docs/eaxscada/reference/sign-in-and-profile-api/
Verified against commit 7fa3985.

How a client signs in to eaxScada, asks who it is, and signs out. Every route of the server, with the role it needs: [HTTP API routes](/docs/eaxscada/reference/generated/http-api/#apiauth).

## Sending the session

A request carries its session in one of these, in this order: an `Authorization: Bearer <token>` header, then (for a live-data socket handshake only) a `token` query parameter, then the `scada_session` cookie. An API token (`eaxt_...`) is sent as a bearer token; it opens no session (see [Connect an MCP client](/docs/eaxscada/how-to/connect-an-mcp-client/)).

eaxScada's own browser pages use the `scada_session` cookie only. They keep no token in Web Storage and send no `Authorization` header. The `token` in the sign-in answer is for programmatic clients. A script that read `localStorage.scada_token` must use an API token instead. See [Where the browser keeps the session](/docs/platform/explanation/security-and-part-11/#71b-where-the-browser-keeps-the-session).

Each request of a session reads the account again. A session whose account is no longer active, or cannot be read from the security store, is refused with `401` (`"status": "unauthorized"`, `"error": "Unauthorized: user account no longer active"`); a page request is sent to the sign-in page instead.

## `POST /api/auth/login`

Public. Body:

```json
{ "username": "jdoe", "password": "..." }
```

| Answer | When |
|---|---|
| `200` | Signed in. Sets the `scada_session` cookie (HttpOnly, SameSite Lax) and returns the body below. |
| `400 {"error": "Invalid JSON"}` | The body is not JSON. |
| `401 {"error": ...}` | Wrong user name or password, or the account is locked or disabled ([account lifecycle](/docs/platform/explanation/security-and-part-11/#4-account-lifecycle-and-iec-62443-sr-13-lockout)). |
| `401 {"error": "sign-in refused: the security store is unavailable; try again in a moment"}` | The security store is reopening or down after a failed write, or could not save this sign-in (its last-login time, a failed attempt, or the reset of an expired lockout). No session is opened, whatever the password. Try again in a moment; the server log says why ([When the security store reopens after a failed write](/docs/platform/explanation/security-and-part-11/#when-the-security-store-reopens-after-a-failed-write)). |
| `403 {"status": "password_change_required"}` | The account still has its first password: no session is opened; change it with `POST /api/auth/change-default-password`. |
| `405` | Not a POST. |

```json
{
  "token": "…",
  "expires_at": 1763300000,
  "user": { "id": "…", "username": "jdoe", "full_name": "…", "roles": ["Shift_Operator"], "groups": [], "status": "active", "…": "…" },
  "permissions": { "user": { … }, "roles": [ … ], "groups": [ … ], "permissions": [ … ], "publish_allow_topics": [ … ], "publish_deny_topics": [ … ], "sub_allow_topics": [ … ], "sub_deny_topics": [ … ] }
}
```

`expires_at` is in Unix seconds. The user never carries a password hash.

## `GET /api/auth/me`

Any signed-in user, and an API token (GET and HEAD only). Returns `{"user", "permissions"}` as at sign-in, plus `api_token` (`id`, `name`, `prefix`, `expires_at`, never the secret) when the caller is an API token. Without a valid session or token: `401 {"error": "not authenticated"}`.

## When the permissions cannot be read

When the server cannot read the caller's roles, groups or rules from the security store, both answers above carry:

```json
{
  "permissions": null,
  "permissions_error": "permissions could not be read; every permission check refuses until the security store is readable"
}
```

The sign-in still opens the session, so that an Administrator can reach security administration and repair the store. Meanwhile every permission check on the server refuses (see [When the security store cannot be read](/docs/platform/explanation/security-and-part-11/#when-the-security-store-cannot-be-read)). A client must treat `permissions: null` as no rights, never as all rights. `permissions_error` is absent when the permissions were read.

While the whole store is reopening or down, no session is opened at all: the sign-in answers `401` "sign-in refused: the security store is unavailable; try again in a moment", and existing sessions get `401` on each request until the store serves again.

## `POST /api/auth/logout`

Any signed-in user (POST only; another method answers `405`). Ends the session, clears the `scada_session` cookie and answers `{"success": true}`.
