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

# Authentication

> OAuth 2.0 client credentials, RS256 tokens, scopes, JWKS, rate limits on the token endpoint, and how to rotate a secret.

The Partners API uses OAuth 2.0 **client credentials**. There is no end-user login and no refresh token.

## Obtain a token

`POST /oauth/token` accepts HTTP Basic (recommended) or `client_id` / `client_secret` in the form body. The only supported `grant_type` is `client_credentials`. The response is always JSON.

```bash cURL theme={null}
curl -s -u "$CLIENT_ID:$CLIENT_SECRET"   -d grant_type=client_credentials   https://partners-sandbox.inra.co.th/oauth/token
```

```python Python theme={null}
import os
import requests

response = requests.post(
    "https://partners-sandbox.inra.co.th/oauth/token",
    data={"grant_type": "client_credentials"},
    auth=(os.environ["CLIENT_ID"], os.environ["CLIENT_SECRET"]),
    timeout=30,
)
response.raise_for_status()
token = response.json()["access_token"]
```

On success:

```json theme={null}
{
  "access_token": "eyJ...",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "companies:search companies:read reports:database reports:offline orders:read"
}
```

On a bad client id or secret, the token endpoint returns the standard OAuth error `invalid_client`, not the `/v1` error envelope.

## Use the token

Send it on every `/v1` request:

```bash theme={null}
Authorization: Bearer $TOKEN
```

The access token is an RS256 JWT, issued for this API (`aud` is `inra-partners-api`), and is valid for **15 minutes**. Request a new one when it is close to expiry. Reusing an expired token returns `401` with the code `unauthorized`.

## Verify a token (optional)

The signing keys are at `GET /.well-known/jwks.json`. The JWT header includes a `kid`:

* Sandbox: `sandbox-1`
* Production: `prod-1`

You do not have to verify the token in order to call the API — the server verifies it on every request — but a backend of your own that receives a token can check the signature, issuer, audience, and expiry.

## Scopes

A token is issued with the scopes granted to your client. The current catalogue is:

| Scope | What it unlocks |
| - | - |
| `companies:search` | `GET /v1/companies`, dictionary list and entries, webhook status |
| `companies:read` | `GET /v1/companies/{company_id}` |
| `reports:database` | `POST /v1/database-reports` |
| `reports:offline` | `POST /v1/offline-reports` and `POST /v1/offline-reports/by-details` |
| `orders:read` | List and read orders, download a report, send a test callback |

If your token is missing a scope, the API returns `403` with the code `insufficient_scope`. Email [inraasth@inra.co.th](mailto:inraasth@inra.co.th) if you need a scope that was not issued.

## Rate limits

Limits are per client and per bucket, and can be agreed individually. The defaults for a new client are:

| Bucket | Default | Applies to |
| - | - | - |
| Token | 30 requests / minute | `POST /oauth/token` |
| Search | 60 requests / minute | Search, lookup, dictionaries, webhook status |
| Report | 10 requests / minute | Placing reports, reading orders, downloading reports, test callbacks |

When you exceed a limit the API returns `429` with the code `rate_limited` and a `Retry-After` header (seconds). Back off and retry.

## Rotate a secret

There is no self-service rotation in v1. If a secret is lost, leaked, or due for a routine change, email [inraasth@inra.co.th](mailto:inraasth@inra.co.th). We will issue a new secret and retire the old one. We will never ask you to paste an existing secret back to us, and these docs will never display one.

Callback signing secrets are also issued by INRA when a callback URL is registered. See [Callbacks](https://docs.partners.inra.co.th/guides/webhooks.md).


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