---
title: "Connect to an OAuth2 provider"
site: admin
version: 1.11
versions: "all"
url: https://docs-new.servicely.ai/admin/1.11/integrations/connect-an-oauth2-provider/
type: task
application: platform_integration
last_updated: 2026-10-18
commit: 5ea5eb0dd83d
---


Connect to an OAuth2 provider when a server script or integration must call a system that uses OAuth2. You end with an outbound token that scripts use by name, and Servicely keeps its access token current.

## Before you begin

- You need the `administrator` role.
- Register Servicely as a client with the provider. For the Authorization Code grant, register the redirect URL `https://<your-instance>/sso/oauth_callback/`.
- Have the client ID, client secret, authorization URL, token URL and scopes from the provider.
- For the Authorization Code grant, have the account that will authorise the token ready to sign in.

## Steps

<Steps>
  <Step>
    Go to **Administration → Integration → System OAuth providers** and select **New**.
  </Step>
  <Step>
    Enter a **Name**, the **Client ID** and the **Client Secret**.
  </Step>
  <Step>
    Set **Grant type** to **Authorization Code** or **Client Credentials**. Use Authorization Code when a user must sign in, and Client Credentials for app-only access.
  </Step>
  <Step>
    Enter the **Token URL** and the default **Scopes**. For Authorization Code, also enter the **Authorization URL** and the **Redirect URL**. Save the provider.
  </Step>
  <Step>
    Go to **Administration → Integration → System API outbound tokens** and select **New**.
  </Step>
  <Step>
    Enter a **Name** and set **Type** to **OAuth2**. Scripts will refer to the token by this name.
  </Step>
  <Step>
    Select the **OAuth Provider** you created. Enter **Scopes** only if this token needs different scopes from the provider. Save the token.
  </Step>
  <Step>
    For Authorization Code, select **Get authorization token**. Sign in at the provider's page and grant consent. The provider returns you to the token form.
  </Step>
  <Step>
    Check that **State** is **Ready**. If it shows **Error**, read **Last message**, correct the provider or token, and repeat the previous step.
  </Step>
</Steps>

<Callout type="info">
  **OAuth Prompt** defaults to consent. Some providers need a different prompt later, for example select_account when an ordinary user signs in. [Outbound credentials](page:integrations/outbound-credentials) lists the values.
</Callout>

## Variations

### Other token types

For a token that does not use OAuth2, create only the outbound token. Set **Type**, then fill in the fields the form shows:

| Type | Fields to fill in |
| --- | --- |
| Basic | **User name** and **Password** |
| Bearer | **Access Key / Token** |
| HMAC Body (Servicely) | **Access Key / Token** and **Secret Key**, from a System API token on the target Servicely instance |
| Access Key | **Access Key / Token** and **Secret Key** |

### Client Credentials

With the Client Credentials grant, nobody signs in. Skip the **Get authorization token** step. Servicely requests an access token from the client ID and secret when the token is first used, and again when it expires.

## Result

The token is active and ready. A server script passes the token name to `apiTokenAuth` on an outbound HTTP request, and Servicely applies the credentials before sending it. Authorization Code tokens are refreshed shortly before they expire. If a refresh fails, **State** changes to **Error** and **Last message** holds the reason.

## Related

- [Outbound credentials](page:integrations/outbound-credentials)
- [Integration methods](page:integrations/integration-methods)
- [Connect Microsoft 365 mail with OAuth2](page:messaging/connect-microsoft-365-oauth2)
