# Credentials

Every request carries one of three credentials. None of them ever goes in the query string.

| Credential | Header | For |
|---|---|---|
| An access token | `Authorization: Bearer cft_<id>.<secret>` | Scripts, integrations, AI agents. Always accepted. |
| A user name and password | `Authorization: Basic ...` | An administrator's own scripts. Can be turned off (Preferences, API). |
| A browser session | the `CrushAuth` cookie and `X-CrushMFT-C2F: <c2f>` | The WebInterface's own pages. Can be turned off. |

A request without a credential, or with one that does not log in, gets **401** with `WWW-Authenticate: Bearer`.

## Who decides

Every answer is decided by the server's roles, the same way for every credential:

- **An administrator** (the Administrator role, or the legacy `CONNECT` flag) may use every operation.
- **An account that holds roles** may use what its roles grant, on the users, jobs and folders they reach.
- **An account on legacy admin flags** (User Admin, Job Admin and the others, without roles) is refused admin operations with the code `legacy_account`. Two ways forward: convert the account to roles (Preferences, Access Roles), or issue it a token, which is always decided by the roles.
- **A user with no admin rights** may use the operations on their own files and account (`/files`, `/me`), by the privileges they have today.
- **A token** may use what it was issued with, and never more than its issuer may do at that moment.

When a request is refused the answer is **403** and its body says why, and which permission was missing. To ask before acting, use `POST /explain` (see [AI agents](API-AI-Agents.md)).

## Tokens

A token is a slice of its issuer's rights:

- **Grants**: the permissions it carries and where they apply, in the form `permission|users=...|jobs=...|storage=...`. For example `users.user.view|users=user:MainUsers/bob` reads one user.
- **Lifetime** in minutes, or none; **max uses**; an **idle timeout**.
- **Read-only**: it reads and never changes anything.
- **Addresses** it may come from, and for file work the **folders**, **privileges** and **protocols** it may use.
- **Propose mode**: its writes change nothing. Each becomes a proposal that its issuer approves or rejects (see [AI agents](API-AI-Agents.md)).

A token **never reaches a tier 0 operation**: one that equals full administration, such as changing the server's access settings or putting back a backup of the preferences. Those need an administrator's own login, by password or browser session. The reference marks them "No token may use it".

Tokens are issued in the User Manager (a user, Access, Access tokens) or with `POST /tokens`, listed with `GET /tokens` and revoked with `DELETE /tokens/{id}`. The secret is shown once, when the token is made, and is never stored readable.

## A user name and password

`Authorization: Basic` logs in as the account, with all of its rights. It is meant for an administrator's own scripts; anything that runs unattended is better off with a token that holds only what it needs.

## A browser session

A page of the WebInterface calls the API with the session it already has: the `CrushAuth` cookie, and its c2f token in the `X-CrushMFT-C2F` header. A form on another site can send neither the header nor a JSON body, so it cannot use a logged-in administrator's session.

[[openapi API/openapi.json tag=access level=2]]
