> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aiveth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Machine-to-machine

> Let a service sign in as itself with the client credentials grant and call your organization's own services.

A machine app is a service that signs in as itself, with no person and no sign-in page. A nightly job, a backend worker or one microservice calling another can each be a machine app. It gets a short-lived token that carries the app permissions you give it, and your own services check that token.

Aiveth implements the OAuth 2.0 client credentials grant (RFC 6749 §4.4). The token is a JWT access token in the shape RFC 9068 describes.

> [!NOTE]
>
> Machine apps need the Pro plan or above.

> [!WARNING]
>
> A machine token is for **your organization's own services**. It opens nothing in Aiveth itself. To manage people in Aiveth from a server, use an [API key](https://docs.aiveth.com/api-reference/authentication.md) instead.

## Set up a machine app

**1. Name your app permissions**

Machine tokens carry your own app permissions. If you have none yet, add them under **Roles** → **Your app permissions**, for example `reports:read`.

**2. Register the app**

Open **Apps** → **Register app**. Under **Kind**, choose **Machine**. A machine app has a secret and no return addresses.

**3. Save the credentials**

Copy the **Client ID** and **Client secret**. The secret is shown once.

**4. Choose what its tokens carry**

Select the app in the list. Under **What its tokens carry**, tick the permissions it may ask for, then select **Save**. The panel also shows the **Token address** and the **Audience** your services check.

## Get a token

```bash theme={null}
curl -X POST https://accounts.aiveth.com/oauth/token \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -d grant_type=client_credentials \
  -d scope="reports:read"
```

```json theme={null}
{
  "access_token": "eyJhbGciOiJSUzI1NiIs...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "reports:read"
}
```

* `scope` is optional. Leave it out to get every permission the app was given. You may ask for fewer, never more; asking for one it wasn't given returns `invalid_scope`.
* You can send the credentials with HTTP Basic or as `client_id` and `client_secret` in the form.
* A machine app can use only `client_credentials`. Any other grant returns `unauthorized_client`.
* There is no refresh token. Ask for a new token when the old one is close to its expiry, and reuse a token until then.

## The token

The token is a JWT signed with RS256, using the same keys as ID tokens (`/v1/auth/.well-known/jwks.json`).

| Claim | Value |
| - | - |
| `iss` | `https://accounts.aiveth.com` |
| `sub`, `client_id` | The machine app's client ID |
| `aud` | `urn:aiveth:org:<your organization ID>` |
| `org_id` | Your organization's ID |
| `scope` | The permissions in this token, space-separated |
| `iat`, `exp` | Issued now; expires one hour later |
| `jti` | A unique ID |
| `gty` | `client-credentials` |

## Check the token in your service

Verify the signature, `iss`, `exp`, that `aud` is your organization's audience, and that `gty` is `client-credentials`. Then check that `scope` holds the permission the call needs.

```ts Node theme={null}
import { Aiveth } from '@gooclaim/aiveth';

const aiveth = new Aiveth({ baseUrl: 'https://accounts.aiveth.com' });
const claims = await aiveth.tokens.verifyMachineToken(token, { orgId: 'YOUR_ORGANIZATION_ID' });

if (!claims.scope.split(' ').includes('reports:read')) {
  // refuse with 403
}
```

```python Python theme={null}
from gooclaim_aiveth_sdk import Aiveth

aiveth = Aiveth("https://accounts.aiveth.com")
claims = aiveth.tokens.verify_machine_token(token, org_id="YOUR_ORGANIZATION_ID")

if "reports:read" not in claims["scope"].split():
    ...  # refuse with 403
```

## Limits and revocation

* Each machine app can get at most 60 tokens a minute. Past that, the token endpoint answers `429` with `slow_down`. Reuse a token until it ends.
* A token can't be called back. Turning the app off or changing its permissions stops **new** tokens; a token already issued lasts until its hour is up. Keep checking `exp`.

## Server-to-server calls for AI agents

If you run MCP servers for AI agents, one server can exchange the token an agent sent it for a token to call another of your servers, for the same person (RFC 8693 token exchange). That is part of the AI agents feature. See [Agent tokens](https://docs.aiveth.com/agents/agent-tokens.md).

## Related

* [Tokens and claims](https://docs.aiveth.com/apps/tokens-and-claims.md)
* [Roles and permissions](https://docs.aiveth.com/access/roles-and-permissions.md)
* [Node SDK](https://docs.aiveth.com/sdks/node.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.