> For the complete documentation index, see [llms.txt](https://docs.idlayr.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.idlayr.com/get-started/authentication.md).

# Authentication

Every call to the IDlayr API requires an OAuth2 access token. **All IDlayr API calls are backend-to-backend** — your server obtains and uses the token directly. The token never leaves your backend and is never given to a mobile app or any other untrusted client.

The mobile SDKs do **not** need an access token. They follow a pre-issued verification URL whose redirect chain is plain HTTP — see [Mobile SDKs](#mobile-sdks) below.

## OAuth2 client credentials grant

```bash
curl -X POST https://{data_residency}.api.idlayr.com/oauth2/token \
  -u "{client_id}:{client_secret}" \
  -d "grant_type=client_credentials" \
  -d "scope={product_scope}"
```

Notes:

* The token endpoint is **unversioned** in v1. The path is `/oauth2/token`, not `/oauth2/v1/token`.
* `{data_residency}` is `eu` or `us`. See [Data residency](/get-started/concepts/data-residency.md).
* `{product_scope}` depends on which product you're calling. See the product's prerequisites for the exact value (e.g. `secure_sna`, `sim_swap`, `reverse_sms`, `eligibility`).
* Authentication is HTTP Basic with `client_id` and `client_secret`.

Response:

```json
{
  "access_token": "...",
  "token_type": "bearer",
  "expires_in": 3600,
  "scope": "secure_sna"
}
```

## Using the access token

Include it as a Bearer token on every API request from your backend:

```
Authorization: Bearer {access_token}
```

Treat the token as a short-lived secret. Don't log it; don't expose it to untrusted clients; **don't ship it to mobile apps or browser code**.

## Token lifecycle

* Access tokens expire after `expires_in` seconds (typically one hour).
* Cache the token on your backend until it expires; request a fresh one before each expiry.
* There is no refresh-token grant for client credentials — re-request with the same flow.
* A token is scoped to one product. To call multiple products, request multiple tokens (one per scope).

## Revoking tokens

The unversioned `/oauth2/revoke` endpoint revokes a specific access token before its natural expiry. Use it if you suspect a token has leaked.

## Mobile SDKs

The iOS and Android SDKs **do not hold or use an OAuth2 access token**. Authentication of the verification round-trip stays on your backend:

1. Your **backend** mints an OAuth2 access token using the project credentials (above).
2. Your **backend** uses that token to create the verification check against the IDlayr API.
3. IDlayr returns a **verification `url`** along with the `check_id`. Your backend hands **only the URL** to your mobile app.
4. Your **mobile app** passes the URL to the SDK. The SDK follows the URL — the device-side step is a redirect chain that doesn't require an `Authorization` header.
5. Your **backend** learns the result via callback (recommended) or by polling.

For the per-product, per-platform code, see each product's iOS / Android integration page.

## Common errors

| HTTP | `error_code`      | Cause                                                             |
| ---- | ----------------- | ----------------------------------------------------------------- |
| 400  | `invalid_request` | Missing or malformed parameter (e.g. no `grant_type`)             |
| 401  | `invalid_client`  | `client_id` or `client_secret` incorrect                          |
| 401  | `unauthorized`    | Project not active, or credentials revoked                        |
| 400  | `invalid_scope`   | The requested scope is unknown or not authorised for this project |

See the API Reference Errors page for the full error taxonomy.

## Related

* [Credentials](/get-started/concepts/credentials.md) — where `client_id` and `client_secret` come from.
* [Project modes](/get-started/concepts/project-modes.md) — sandbox tokens come from the same endpoint but operate against simulated traffic.
* Cloudsmith entitlement tokens for SDK distribution (build-time, distinct from runtime API authentication) — see [SDKs](/get-started/sdks.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.idlayr.com/get-started/authentication.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
