# Authentication

> Keys, modes and scopes, how the first key is made, and how an agent signs in as a person instead

Source: https://tickets.roostertail.com/docs/authentication

## Keys

Send a key as `Authorization: Bearer rt_test_…` from your server. The key decides two things, and you never send either: the **organization** (one key is one org's) and the **mode** (`rt_test_` is test, `rt_live_` is live). Test and live data never mix.

There is **no publishable key**. A key never goes in a browser page, a mobile app or a public repository. That is why a checkout needs a small server of your own, and why [the kit](https://tickets.roostertail.com/docs/kit.md) has one.

| Scope | May | Sees |
| --- | --- | --- |
| `full` | Everything an API key can do. | Everything. |
| `read` | Every `GET`, and the searches that only read. | What opens the door or a holder's page is `null`, in event log rows too: a ticket's QR text and page link, an order's private link, a code's text. No QR image. |
| `checkin` | The door endpoints: scan, look up, stats, the offline manifest. | Guests' names in short form. |

A call outside a key's scope answers 403 `insufficient_scope`. Ask a key what it is before an agent writes anything:

```ts
const me = await tickets.keys.current();
console.log(me.mode, me.scope, me.hint.length > 0); // test full true
```

`hint` is the last characters of the secret, so you can tell your keys apart. The secret is never readable again after it was made.

## How the first key is made

A key is made by a **person** in a signed-in dashboard session, never by another key. This is on purpose: a leaked key must not be able to make more keys.

1. The person signs in at `/login` with their email. There are no passwords: a six-digit code or a link is emailed to them.
2. A first sign-in makes their organization.
3. Under Developers, API keys, Create API key: pick a name and a scope, then copy the secret. It is shown once. The dashboard makes a test key.
4. They give the secret to the agent or the server in `RCMS_TICKETS_KEY`.

Rolling a key (`POST /v1/keys/{id}/roll`) makes a new secret and keeps the old one working for a time you choose, so a secret can change without downtime. Revoking (`POST /v1/keys/{id}/revoke`) stops it now and cannot be undone. Both are done in the dashboard too.

> **Not open to the public yet.** RCMS Tickets is in development. Mail stays in an outbox on this host, so a sign-in code reaches only the people we let in, and a test key works today. Live mode is open only for an organization we have cleared. A live key can be made, and for any other organization every call it makes answers `live_mode_not_open`.

## An agent without a key: sign in as the person

An agent that works for several clients should not hold a key per client. It can connect to [the MCP server](https://tickets.roostertail.com/docs/mcp.md) and **sign in as the person**: the person approves it once on a consent page, choosing read only or full, and the agent then acts as them, in any organization they belong to, naming the organization and the mode on every call. The agent never holds a secret that lasts: its access renews every 15 minutes, and the person ends the connection under Settings.

A key stays one organization's, so a leaked key can reach one client, never all of them.

## Other ways in

| Who | How | For |
| --- | --- | --- |
| A person | A session cookie from the emailed code, 7 days idle | The dashboard. Roles: owner, admin, staff, door, viewer. |
| A door phone | A device token `rtd_…`, from pairing | Scanning, and gate sales if allowed. [The door](https://tickets.roostertail.com/docs/door.md) |
| A ticket holder | A private link (`/t/…`), or a code to their email or phone | Their own tickets. |
| A partner | A private page link (`/p#…`) | Their own numbers. [Partners and their pages](https://tickets.roostertail.com/docs/tracking.md) |

## Test it with curl

```bash
export API=https://rcms-tickets-test.web.app/v1

curl -sS "$API/keys/current" -H "Authorization: Bearer $RCMS_TICKETS_KEY" | jq '{mode, scope}'
curl -sS -o /dev/null -w '%{http_code}\n' "$API/keys/current"
curl -sS "$API/keys/current" -H "Authorization: Bearer rt_test_nope" | jq -r .error.code
```

The second call has no key and answers 401 `missing_api_key`. The third has a key that is not one of ours: `invalid_api_key`. A revoked key answers `api_key_revoked`.
