# Authentication

Every call carries a bearer token in the `Authorization` header. The kind of token decides which operations you can call.

*Request header*

```http
Authorization: Bearer <token>
```

## The kinds of credential

| Kind | Prefix | Acts as | Calls | Status |
|---|---|---|---|---|
| [Personal access token](#personal-tokens) | `kanso_pat_` | one internal member of one tenant, narrowed by its abilities | 69 operations of the token catalogue | Available |
| [Help-desk service token](#help-desk-tokens) | `kanso_hdt_` | one help-desk connection — never a person | the 10 operations under `/help-desk/…` | Available |
| [Agent token](#agent-tokens) | `kanso_agt_` | one agent identity, within its owner's access | the 24 operations under `/agent/…` and `/mcp` | Available |
| [Browser session](#sessions) | — | the signed-in person | the Youniton apps only | App only |

A token works only on the operations of its kind. A help-desk token on another operation, or a personal token on a help-desk operation, answers `403 service_token.not_allowed_here`. A personal token on an operation outside its catalogue answers `404 route.not_found`.

## Personal access tokens

A member creates a token on **Account › Sessions & apps › API tokens**. The token belongs to that member in the current tenant and acts as that member. Every write is recorded for the member with the source `api`.

### Abilities

Select 1 to 15 abilities. An ability only narrows: a call needs the ability *and* the member's role capabilities *and* the access rules of the record. A token never does more than its member can do.

| Ability | What it opens |
|---|---|
| `projects:read` | the project list, one project and its field schema |
| `tickets:read` | ticket lists, boards, backlogs, sprints, epics, labels, timeline, a ticket with its comments, attachments, activity and merge requests |
| `tickets:write` | create, edit, position and client visibility of tickets |
| `comments:write` | post a comment on a ticket |
| `time:read` | worklogs, week grids, team periods and timesheets |
| `time:write` | log, edit and delete your own worklogs; submit and withdraw your own timesheets |
| `docs:read` | doc pages, their revisions and versions |
| `search:read` | `GET /search` |
| `relationships:read` · `relationships:write` | client organisations and contacts |
| `messages:read` · `messages:write` | your direct and group conversations and the project conversations in your scope |
| `memory:read` · `memory:write` | the memory entries and directories of a project (and the knowledge items) |
| `transcripts:read` | no operation of its own: it admits meeting-transcript items on the memory operations |

`memory:write` and `transcripts:read` need `memory:read`. A token with a memory ability can also be narrowed to chosen memory segments (`memorySegments`, 1–100 keys). The set never changes; for another set, create a new token.

Out of v1 for personal tokens: administration, the platform API, the assistant, exports and imports, uploads, client actions, previews, and the management of automation rules, webhook endpoints and custom fields.

### Expiry

- Expiry is mandatory: 30, 90 or 365 days. An Admin can set a shorter maximum for the tenant; then the maximum is one more choice.
- A value above the maximum answers `422 token.expiry_exceeds_policy`. Another value answers `422 token.expiry_not_offered`.
- An expired token answers `401 auth.unauthenticated`. Youniton deletes it 24 hours after expiry.

### The secret

Youniton shows the secret one time, at creation. It stores only a keyed hash, so nobody can show the secret again. The list shows a masked preview, for example `kanso_pat_7Hq2…x9Lm`, the creation time, the last use and the expiry. The prefix lets secret scanners find a leaked token.

### Rotation

To rotate a personal token, create a new token, change your script to the new secret, then revoke the old token. Two tokens can be live at the same time.

### Revocation

Select **Revoke** in the token list. The token stops at once: the next call answers `401 auth.unauthenticated`.

> **Youniton also revokes tokens**
>
> - when the member is removed from the tenant, or the account is disabled or recovered;
> - when an Admin turns tokens off for the tenant (Administration › Security & sign-in › API tokens);
> - when the tenant is suspended. Until the revocation runs, a call answers `403 tenant.suspended`.

### Tenant header

The token names its tenant, so you do not need `X-Kanso-Tenant`. When you send it, it must equal the token's tenant.

## Help-desk service tokens

An Admin creates a help-desk connection in **Administration › Help desk** and issues its token. The connection names one project and one client organisation. The token acts only as that connection.

- **Abilities** belong to the connection: `requests:create`, `requests:read`, `requests:reply` and `files:upload`. A missing ability answers `403 help_desk.ability_missing`.
- **Expiry** is mandatory: 30, 90, 180 or 365 days.
- **Rotation** keeps the old token for an overlap, so the client's system changes its secret with no downtime. A connection has at most two live tokens.
- **Revocation** deletes the token: the next call answers `401 auth.unauthenticated`. When the Admin who issued the token leaves, the token stays: the connection belongs to the tenant.
- A paused connection answers `403 help_desk.connection_paused`.

Read the full flow in [Create help-desk requests](https://docs.youniton.com/api/guides/help-desk-requests.md).

## Agent tokens

An agent token (`kanso_agt_…`) belongs to an **agent identity**: an AI agent, a service such as CI, or a meeting assistant. An Admin creates the identity in **Administration › Agents** and issues its token. A tenant setting can also let members create identities that they own.

- The token calls the agent API under `/api/v1/agent/…` and the MCP server at `/mcp`, and nothing else.
- The identity acts within the intersection of its owner's current access, its projects and its abilities. It never acts as a person.
- Youniton shows the secret one time. A token has an expiry. **Rotation** gives a new secret with an overlap. **Revocation** stops the token at once.
- When the owner leaves the tenant, the identity is suspended. An Admin can pause, resume, transfer and revoke an identity.

Read [Coding agents & MCP](https://docs.youniton.com/api/tools/coding-agents-mcp.md).

## Browser sessions

The Youniton apps use a session cookie with CSRF protection. Do not use a session for an integration: it ends at sign-out, at an idle timeout and at a password change. Operations that only accept a session are marked *Session (app only)* in the reference.

## Keep tokens safe

- Call the API from your server. The public API sends no CORS headers, so browser code on another origin cannot call it.
- Give each script its own token with the fewest abilities and the shortest expiry that works.
- Keep the secret in an environment variable or a secret store. Never put it in a document, a log, a commit or a chat.
- Revoke a token at once when you think that someone saw it.
