# Connect an API that uses Auth0

If your API verifies access tokens issued by Auth0, Faustine signs in as a machine-to-machine application, with the client credentials grant. You create that application in Auth0 and enter its values in Faustine.

## Before you begin

- Your API is registered in Auth0 and has an identifier, such as `https://api.nimbuscrm.example`. Auth0 uses the identifier as the token's audience.

## Create the application in Auth0

In Auth0, create a machine-to-machine application for Faustine and authorize it for your API, with the permissions agent traffic needs. For the screens, see [Machine-to-machine applications](https://auth0.com/docs/get-started/auth0-overview/create-applications/machine-to-machine-apps) and [the client credentials flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow) in the Auth0 documentation.

Note four values: your Auth0 domain, the API's identifier, and the application's client ID and client secret.

## Set the token endpoint on the API

1. In the portal, go to [**APIs**](https://auth.faustine.ai/go?to=%2Fintegrations%2Fapis) and select your API.
2. Select the **Authentication** tab, then **Edit**.
3. In **Sign-in method**, select **OAuth client**.
4. In **Token provider**, select **Auth0**.
5. In **Domain**, enter your Auth0 domain, such as `acme.us.auth0.com`.
6. In **Audience**, enter the identifier of your API. Auth0 does not issue a token without it.
7. **Scopes** is optional.
8. Select **Save changes**.

The token URL appears under **Domain**:

```text
https://<DOMAIN>/oauth/token
```

A custom domain works in **Domain** too. The next time you open the form, it shows the provider as **Custom** with the same token URL.

## Add the client to a connection

1. Select the **Connections** tab, then **New connection**, or select an existing connection.
2. In **Credentials**, enter the **Client ID** and **Client secret**.
3. In the **Test** step, select a read operation and select **Test connection**.

**Reached the endpoint** with a `2xx` status confirms that Auth0 issued a token and your API accepted it.

## Troubleshooting

| Symptom | Cause | Fix |
| --- | --- | --- |
| `Auth0 needs the API identifier as the audience.` | **Audience** is empty. | Enter the identifier of the API as registered in Auth0. |
| `Identity provider refused the client credentials`, with `access_denied` | The application is not authorized for the API named in **Audience**. | Authorize the application for that API in Auth0. |

## Next steps

- [Connect with an OAuth client](https://docs.faustine.ai/apis/connect-with-an-oauth-client/): every field of the strategy and how the token is renewed.
- [Add a connection](https://docs.faustine.ai/apis/add-a-connection/): the full wizard.
- [Authentication](https://docs.faustine.ai/apis/authentication/): the other strategies.
