# Authentication

> The kinds of credential Naruska CRM accepts, what each is for, and the scopes that limit them.

Every request carries a bearer token in the `Authorization` header. Which kind you use depends on who is calling.

## Kinds of credential

| Credential                         | Looks like                  | For                                                        | Acts as                                          |
| ---------------------------------- | --------------------------- | ---------------------------------------------------------- | ------------------------------------------------ |
| OAuth sign-in                      | a short-lived access token  | AI tools (Claude, ChatGPT, Copilot Studio) and the web app | the person who signed in, with all their rights  |
| Personal access token              | `nrk_pat_…`                 | your own scripts                                           | you, limited to the token's scopes               |
| Service account client credentials | a client id and `nrk_sec_…` | integrations that run on their own                         | the service account, limited to its scopes       |
| API key                            | `nrk_key_…`                 | integrations that can only send one fixed key              | the service account, limited to the key's scopes |

- **AI tools sign in with OAuth.** You sign in with your Google, Microsoft or Apple account and approve the tool once; the tool keeps its own token and renews it. You never paste a token into an AI tool. See [Connect your AI tool](/connect.md).
- **Personal access tokens** expire after 90 days by default, at most a year.
- **Service accounts** belong to the company, not a person, so an integration keeps working when someone leaves. Admins create them. A service account exchanges its client id and secret at `POST https://staging-api.naruskacrm.com/oauth/token` (OAuth client credentials) for an access token that is valid for 15 minutes.
- **API keys** belong to a service account too. Prefer client credentials where your integration can do it: a leaked access token stops working within 15 minutes.

Secrets are shown once, when they are created. Naruska CRM keeps only a fingerprint of each, so a lost secret can't be shown again: revoke it and create a new one.

## Creating credentials

Creating tokens, service accounts and API keys in Settings comes later. Until then the routes are in the [Credentials API reference](/api/reference/credentials.md); they work only for a person signed in to the web app, never with a token.

## Scopes

Personal access tokens, service accounts and API keys carry scopes. The API checks the scope; your role and the records' sharing still decide which records you see.

| Scope             | Allows                                                       |
| ----------------- | ------------------------------------------------------------ |
| `records:read`    | reading records, lists, search, timelines and the data model |
| `records:write`   | creating and changing records, and undo                      |
| `records:delete`  | deleting and restoring records                               |
| `webhooks:manage` | managing webhook endpoints (admins)                          |
| `usage:read`      | reading the company's usage and limits                       |

OAuth sign-ins have no scopes: they act with the person's full rights. A request without the scope it needs is refused with [`insufficient_scope`](/errors/insufficient_scope.md).

## When a token stops working

- [`token_expired`](/errors/token_expired.md): get a new one. AI tools do this by themselves.
- [`token_revoked`](/errors/token_revoked.md): someone revoked it; create a new one.
- [`user_deactivated`](/errors/user_deactivated.md): the person or service account behind it was deactivated.
