# OAuth: an application gets its token by itself

Without OAuth, an application that calls the API needs an [access token](API-Authentication.md#tokens) that someone made for it by hand and pasted into it. With OAuth on, the application gets its token by itself, the standard way (OAuth 2.1):

| Way | For | How it proves itself |
|---|---|---|
| **A person connects it** | AI clients such as Claude Code, desktop and command-line tools, a web application | the person signs in on this server and allows it on a page of the server's; the application then keeps its connection |
| **It signs in by itself** | a service of your own: an export at night, an integration | a client secret, or a key of its own (`private_key_jwt`); it acts as one account |
| **It brings a token of its own platform** | GitHub Actions, Kubernetes, Entra ID, Okta, Google | a signed token (a JWT) from an issuer you trust for it; it acts as one account |

Whichever way, the application gets an ordinary access token (`cft_...`). The same roles and checks decide what it may do as for a token made by hand, and it never reaches an operation that equals full administration.

## Turn it on

1. In [Preferences, API](Prefs-API.md), turn the API on, and for AI clients **Offer the MCP endpoint**.
2. In the **OAuth** card, tick **Applications may get their own tokens** and fill in the **Sign-in address**: the address people sign in at, such as `https://files.example.com`. Applications are given it as this server's name (the issuer). The [App Gateway](Security-App-Gateway.md) uses the same one.
3. **Save**.

OAuth needs the API feature of the license. It works while all four are true: OAuth on, the API on, the license, and a sign-in address.

![The OAuth card](API-OAuth/settings.png)

| Setting | Key | What it does | Default |
|---|---|---|---|
| **Applications may get their own tokens** | `api_oauth_enabled` | OAuth on. Off ends every token an application got this way, at once. | off |
| **Sign-in address** | `gateway_login_url` | https and the host where people sign in, with no path | empty |
| **Other addresses** | `api_oauth_addresses` | other addresses the API is reached at, one a line. A token is made for one address and taken only there. | empty |
| **A token lasts** | `api_oauth_access_minutes` | the life of an access token, 1 to 1440 minutes | 60 |
| **A connection lasts** | `api_oauth_refresh_days` | how long an application stays connected before the person signs in again, 1 to 3650 days | 30 |
| **and ends after ... days without use** | `api_oauth_refresh_idle_days` | a connection nobody used this long ends | 14 |
| **Let people connect applications that name themselves by a web address** | `api_oauth_outside` | applications nobody registered here may connect (see below). Off ends their tokens at once. | off |
| **Only from these hosts** | `api_oauth_outside_hosts` | only such applications whose address is on these hosts, one a line, `*.example.com` for every name under it | empty: any |
| **They may** | `api_oauth_outside_level` | **Do what the person may**, or **Only read** | Do what the person may |
| **Who may connect them** | `api_oauth_outside_who`, `api_oauth_outside_roles` | anyone who can sign in, or only the holders of the roles named | anyone |
| **They stay connected (refresh tokens)** | `api_oauth_outside_refresh` | off: the person signs in again each time the token runs out | on |

**For an AI client, give it** shows the address of the MCP endpoint, with a button that copies it.

## Connect Claude Code, or another AI client

Claude Code and most AI clients name themselves by a web address (a Client ID Metadata Document) instead of being registered on each server. So first tick **Let people connect applications that name themselves by a web address** on the OAuth card; to take only Claude's, put `claude.ai` in **Only from these hosts**. Then add the server to the client:

```
claude mcp add --transport http crushmft https://files.example.com/WebInterface/api/v1/mcp
```

The first call answers 401 and points to this server's sign-in, which the client finds by itself. Claude Code then asks you to authenticate (`/mcp`): the browser opens the server's sign-in page and then the page that asks whether to connect it. After **Allow**, the client holds a token for the MCP endpoint and gets a new one by itself whenever it runs out, for as long as the connection lasts.

## The page that asks the person

![The page that asks whether to connect an application](API-OAuth/consent.png)

The person sees which application asks and as which account, chooses what it may do (**Only read** is always offered) and sees where the browser goes next. For an application nobody registered, the page leads with the host its address is on, since its name is only its own claim. For an application on the person's own computer, the page warns to allow it only if they started it themselves.

## Register an application

Applications you know get a registration of their own: **Applications**, **Add application** on the same page.

![The list of applications](API-OAuth/applications.png)

![An application that people connect](API-OAuth/application.png)

| Field | What it does |
|---|---|
| **Name** | shown on the page that asks the person, and in every list |
| **Enabled** | off: it gets no token, the tokens it holds end at once, and its connections stop |
| **Kind** | **People connect it to their own account**, or **It signs in by itself, as one account**. It cannot be changed later. |
| **Installed on a device or running in a browser: no secret** | such an application proves itself with PKCE alone. Off: it signs in with a client secret, made when it is saved and shown that once, or with its public keys. |
| **Redirect addresses** | where the browser may be sent back, matched exactly: an https address; an http address only on the person's own computer (127.0.0.1, [::1] or localhost), where any port is taken; or an app's own scheme such as `com.example.app:/callback` |
| **Ask the person first** | off: nobody is asked, you vouch for the application yourself |
| **Who may connect it** | anyone who can sign in, or only the holders of some roles |
| **It stays connected (refresh tokens)**, **For at most** | it gets a refresh token, and how many days its connections may last at most |
| **Level** | **What the account may do**, or **Only read** |
| **Only these permissions** | narrows its tokens to these permissions, or to every permission that begins with a name ending in a dot, such as `users.` |
| **Its tokens are for** | **The MCP endpoint**, **The API** (the MCP endpoint included), or **Everything a token reaches over HTTP**: the API, WebDAV and transfers |
| **A token lasts** | its own token life in minutes; empty: as the OAuth card says |

**What to give the application** lists its client id, the issuer and the two endpoints. **New client secret** makes a new secret and shows it once; the old one stops working at once.

## An application that signs in by itself

With **It signs in by itself, as one account**, the application acts as the **Account** named (a connection group and a user name). The account must exist and have been saved once in the User Manager; an account deleted and made again under the same name is not it. **Only from these addresses** limits where its requests, and its tokens, are taken from.

It asks for a token with its client id and secret:

```
curl -u oc_7f3a91c2b4d5e6f7:<client secret> -d grant_type=client_credentials -d scope=api https://files.example.com/oidc/token
```

The answer holds `access_token`, which it sends as `Authorization: Bearer cft_...` until it runs out, then asks again. Instead of a secret it may sign in with a key of its own: put its public keys (a JWKS) in **Its public keys**.

## A token of its own platform

A job in GitHub Actions, a pod in Kubernetes or an application in Entra ID, Okta or Google already holds a token its platform signed. Under **Trust a token of its own platform**, add a row for it: the **Issuer**, the **Subject** the token names (the workload), the **Audience** it is made for, and optionally the **Keys address**; the examples fill in a row for each platform. The application then trades its platform's token for one of this server's:

```
curl -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer -d client_id=oc_7f3a91c2b4d5e6f7 -d assertion=<the platform's token> https://files.example.com/oidc/token
```

**Test** fetches the issuer's keys now and shows what came: the keys, and the certificate the address showed. The keys are taken only from an address whose certificate a trusted certificate authority issued, or one that matches a pin the server already has. For an issuer inside your network with a certificate of its own, **Test** says it was refused and shows that certificate; if you trust it, add its host to Always Trusted Domains ([Certificate pinning](Security-Certificate-Pinning.md)).

## What a token may do

- What the account may do **at the moment of use**: a role taken from the account is gone from the token's next request.
- Never more than the application's **Level** and **Only these permissions**, nor more than the person chose on the page that asked them.
- Never an operation that equals full administration, whatever the application or the account.
- Only where it is for (**Its tokens are for**), and only at the address it was made for.

## Connected apps

A person's connections are in the User Manager: the user, **Admin**, **Access**, **Connected apps**. **Disconnect** ends a connection and its tokens at once, on every server of a cluster. See [Admin](Users-Admin.md).

Through the API a person lists and ends their own with `GET /me/connections` and `DELETE /me/connections/{id}`; an administrator sees everyone's with `GET /oauth/connections`.

## In a cluster

The settings and the applications go to the other servers with the preferences, when the cluster replicates them. Tokens and connections are on every server, and ending one works on every server at once.

## Not yet

- **Through a DMZ:** the sign-in and the token addresses are not answered through a DMZ yet. A client on the person's own computer, such as Claude Code, needs none. A service in the cloud, such as an AI assistant's connector, can reach only a server that faces the internet itself.
- **Dynamic Client Registration** is not offered: applications nobody registered name themselves by their web address instead.

## The addresses

| Address | What it is |
|---|---|
| `https://files.example.com` | the issuer: the sign-in address |
| `/oidc/authorize` | where the browser is sent to sign in and allow (PKCE required) |
| `/oidc/token` | where an application gets and renews its tokens |
| `/oidc/revoke` | where an application ends a token or its connection when it signs out |
| `/.well-known/oauth-authorization-server` | the server's own description for applications |
| `/.well-known/oauth-protected-resource` | what the API and the MCP endpoint say about themselves |
| `/WebInterface/api/v1/mcp` | the MCP endpoint |

## The API's operations

The settings, the applications and the connections, as the pages above show them. Reading the settings and the applications needs **access.oauth.view**, changing them **access.oauth.edit**, and everyone's connections **access.tokens.view-all** and **access.tokens.revoke-all**; a person's own need nothing more than their login. No token may change OAuth or end a connection.

[[openapi API/openapi.json tag=oauth]]
