---
title: "Connect to an OAuth2 provider"
site: admin
version: 2027.1
versions: "all"
url: https://docs-new.servicely.ai/admin/2027.1/integrations/connect-an-oauth2-provider/
type: task
application: platform_integration
last_updated: 2026-12-03
commit: 6777698daac5
---


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.

<Callout type="info">
  **Changed in 2027.1.** A provider has **Use PKCE** and **Withdrawn** fields, and a token has **Allowed Hosts**. Servicely refuses a token that is inactive, has a withdrawn provider, or goes to a host outside **Allowed Hosts**. No action is needed on upgrade.
</Callout>

## 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://<instance>.servicely.ai/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 **Integrations → API access → System OAuth providers** and select **New**. To start from a provider's usual values, open the templates menu at the top right. It offers **Google**, **Microsoft**, **Microsoft - Multitenant** and **ServiceNow**.

    <Image src="asset:screenshots/admin/integrations-connect-an-oauth2-provider/nav-api-access.png">The System OAuth providers item in the API access menu of Integrations.</Image>

    <Image src="asset:screenshots/admin/integrations-connect-an-oauth2-provider/new-oauth-provider.png">The empty Create System OAuth Provider form.</Image>
  </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**. Set **Use PKCE** to **Yes** if the provider expects a PKCE code challenge. Select **Create**.
  </Step>
  <Step>
    Go to **Integrations → API access → System API outbound tokens** and select **New**.
  </Step>
  <Step>
    Enter a **Name** and set **Type** to **OAuth2**. **Key** fills in from the name. Scripts refer to the token by its name or its key.

    <Image src="asset:screenshots/admin/integrations-connect-an-oauth2-provider/new-oauth2-outbound-token.png">A new System API Outbound Token with Type set to OAuth2.</Image>
  </Step>
  <Step>
    Select the **OAuth Provider** you created. Enter **Scopes** only if this token needs different scopes from the provider. In **Allowed Hosts**, enter the host names the token may be sent to, for example `api.example.com`. Select **Create**.
  </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 or key to `apiTokenAuth` on an outbound HTTP request. 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. If the request goes to a host outside **Allowed Hosts**, Servicely refuses it before sending anything.

## 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)
