---
schema_version: "1"
id: c99f46aed574d1e7f17d95d3dedb1b520d007773f32ae538a5d3df6209b2b02b
title: OAuth 2.0 Client Credentials Flow for Server-to-Server Integration
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/remoteaccess_oauth_client_credentials_flow_ca.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_oauth_client_credentials_flow_ca.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: e50e18937c48d66c5ecfa1e1b6a3ed4a48b93dc0c2a484f4cb75c16642f41020
description: Sometimes you want to directly share information between two applications without a user getting in the way. For these scenarios, you can use the OAuth 2.0 client credentials flow. In this flow, the client app exchanges its client credentials defined in the connected app—its consumer key and consumer secret—for an access token. This flow eliminates the need for explicit user interaction, though it does require you to specify an integration user to run the integration. You can use this flow as a more secure alternative to the OAuth 2.0 username-password flow.
products:
  - Security
  - Cross Cloud
release: "264"
---
# OAuth 2.0 Client Credentials Flow for Server-to-Server Integration

Sometimes you want to directly share information between two applications without a user getting in the way. For these scenarios, you can use the OAuth 2.0 client credentials flow. In this flow, the client app exchanges its client credentials defined in the connected app—its consumer key and consumer secret—for an access token. This flow eliminates the need for explicit user interaction, though it does require you to specify an integration user to run the integration. You can use this flow as a more secure alternative to the OAuth 2.0 username-password flow.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>All</strong> Editions</td></tr></tbody></table>

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-identity-264-0-0-production-enus/699dab6f-8f1a-4662-b24f-6521d5b747f7/images/icon_note.png)

Note Connected apps creation is restricted as of Spring ‘26. You can continue to use existing connected apps during and after Spring ‘26. However, we recommend using [external client apps](https://help.salesforce.com/s/articleView?id=xcloud.external_client_apps.htm&language=en_US) instead. If you must continue creating connected apps, contact Salesforce Support.

See [New connected apps can no longer be created in Spring ‘26](https://help.salesforce.com/s/articleView?id=005228017&type=1&language=en_US) for more details.

To use the client credentials flow, you must create a connected app and configure its OAuth settings and access policies.

For example, you build a custom app to run automated reports from Salesforce. You want the app to run reports every night. To integrate your custom app with Salesforce, you set up a connected app. Then, to configure your connected app for the client credentials flow, you enable the flow and assign an integration user. When the nightly report service kicks off, your custom app accesses Salesforce data using these high-level steps.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-identity-264-0-0-production-enus/699dab6f-8f1a-4662-b24f-6521d5b747f7/images/icon_note.png)

Note This flow doesn’t support refresh tokens.

1. The connected app sends its client credentials to the Salesforce OAuth token endpoint via a POST request.
2. Salesforce validates the client credentials and authenticates the app.
3. Salesforce returns an access token on behalf of the integration user you assigned.
4. The connected app uses the access token to call a Salesforce API, such as REST API.
5. The API responds with the requested data for the report.

![Warning](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-identity-264-0-0-production-enus/699dab6f-8f1a-4662-b24f-6521d5b747f7/images/icon_warning.png)

Warning Before you set up the client credentials flow, it’s important to understand its security risks. With this flow enabled, any person or app that has access to your connected app’s consumer key and consumer secret can get an access token. Maintain security by periodically changing your consumer secret, and change it immediately if it becomes compromised. See [Rotate the Consumer Key and Consumer Secret of a Connected App](https://help.salesforce.com/s/articleView?id=xcloud.connected_app_rotate_consumer_details.htm&type=5&language=en_US).

## Request an Access Token

Let’s break down the process of getting an access token with the client credentials flow.

To initiate the flow, the connected app posts its client credentials to the Salesforce token endpoint. You can include the client credentials as parameters in the body of the request. Or, for added security, put your client credentials in a Basic authorization header.

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-identity-264-0-0-production-enus/699dab6f-8f1a-4662-b24f-6521d5b747f7/images/icon_important.png)

Important When developing OAuth integrations, always pass sensitive information in the body of a POST request or in a request header. Don't use GET parameters in the URL query string to pass sensitive information. Sensitive information includes but isn't limited to usernames, passwords, OAuth tokens, client secrets, and any personally identifiable information. For more information on security best practices, see [Storing Sensitive Data](https://developer.salesforce.com/docs/atlas.en-us.secure_coding_guide.meta/secure_coding_guide/secure_coding_storing_sensitive_data.htm) in the Secure Coding Guide.

Here’s an example POST request with the client credentials in the request body.

```
POST /services/oauth2/token HTTP/1.1
Host: MyDomainName.my.salesforce.com
grant_type=client_credentials&
client_id=*******************&
client_secret=*******************
```

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-identity-264-0-0-production-enus/699dab6f-8f1a-4662-b24f-6521d5b747f7/images/icon_note.png)

Note To find your My Domain URL, from Setup, in the Quick Find box, enter My Domain, and then select **My Domain**.

These parameters must be included in the request.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d4012e137">Parameter</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d4012e140">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e137 "><code>client_id</code></td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e140 ">The consumer key of the connected app. To access the consumer key, from the App
              Manager, find the connected app and select <strong class="uicontrol">View</strong> from the
              dropdown. Then click <strong class="uicontrol">Manage Consumer Details</strong>. You're
              sometimes prompted to verify your identity before you can view the consumer
              key.</td>

          </tr>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e137 "><code>client_secret</code></td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e140 ">The consumer secret of the connected app. To access the consumer secret, from
              the App Manager, find the connected app and select <strong class="uicontrol">View</strong> from
              the dropdown. Then click <strong class="uicontrol">Manage Consumer Details</strong>. You're
              sometimes prompted to verify your identity before you can view the consumer
              secret.</td>

          </tr>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e137 "><code>grant_type</code></td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e140 ">
              <p><span>The OAuth 2.0 grant type that the connected app requests.</span> For the
                client credentials flow, this value must be set to
                <code>client_credentials</code>.
              </p>
              <p style="margin-bottom:0;">For a detailed explanation of the client
                credentials grant type, see section <a href="https://www.rfc-editor.org/rfc/rfc6749#section-4.4" target="_blank">4.4 Client Credentials Grant</a> in <cite>The OAuth 2.0
                  Authorization Framework</cite> from the Internet Engineering Task
                Force.</p>
            </td>

          </tr>
        </tbody>
      </table>

Here’s an example with the client credentials in a Basic authorization header. With this format, the `client_id` is appended to the `client_secret` in the format `client_id:client_secret`, and the resulting value is Base64-encoded.

```
POST /services/oauth2/token HTTP/1.1
Host: MyDomainName.my.salesforce.com
Header: Authorization: Basic 
TXlDbGllbnRJRDpNeUNsaWVudFNlY3JldA==
grant_type=client_credentials
```

If you use this format, the `grant_type` is the only required parameter in the request body. The `grant_type` must be set to `client_credentials`.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-identity-264-0-0-production-enus/699dab6f-8f1a-4662-b24f-6521d5b747f7/images/icon_note.png)

Note Because Salesforce doesn’t support scopes on the token endpoint, you can’t include scopes in the request. Instead, assign scopes to your connected app.

## Salesforce Grants an Access Token

After validating the client credentials, Salesforce returns a response containing an access token and requested scopes. The app can use the access token to access protected data in Salesforce.

Here’s an example access token response in JSON format.

```json
{
    "access_token": "*******************",
    "instance_url": "https://yourInstance.salesforce.com",
    "id": "https://login.salesforce.com/id/XXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXX",
    "token_type": "Bearer",
    "scope": "id api",
    "issued_at": "1657741493799",
    "signature": "c2lnbmF0dXJl"
}
```

These parameters are included in the response.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d4012e260">Parameter</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d4012e263">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e260 ">
              <code>access_token</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e263 ">OAuth token that a connected app uses to request access to a protected resource
              on behalf of the client application. Additional permissions in the form of scopes
              can accompany the access token.</td>

          </tr>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e260 ">
              <code>instance_url</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e263 ">A URL indicating the instance of the user’s org. For example:
              <code>https://<var>yourInstance</var>.salesforce.com/</code>.
            </td>

          </tr>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e260 ">
              <code>id</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e263 ">An identity URL that can be used to identify the org and integration user. The
              format of the URL is
              <code>https://login.salesforce.com/id/<samp class="parmname">orgID</samp>/<samp class="parmname">userID</samp></code>.
            </td>

          </tr>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e260 ">
              <code>token_type</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e263 ">
              <span>A <code>Bearer</code> token type, which is used for all responses that
                include an access token.</span>
            </td>

          </tr>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e260 ">
              <code>scope</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e263 ">
              <p>The scopes associated with the access token.</p>
              <p>Scopes further define the type
                of protected resources that the client can access. You assign scopes to a
                connected app when you build it, and they’re included with the OAuth tokens during
                the authorization flow.</p>
              <p>Because the client credentials flow doesn’t support
                UI sessions and doesn’t issue a refresh token, Salesforce automatically filters
                out these scopes.</p>
              <ul>
                <li><strong class="uicontrol">Full access</strong> (<code>full</code>)</li>

                <li><strong class="uicontrol">Manage user data via Web browsers</strong>
                  (<code>web</code>)</li>

                <li><strong class="uicontrol">Perform requests at any time</strong>(<code>refresh_token,
                      offline_access</code>)</li>

              </ul>
            </td>

          </tr>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e260 ">
              <code>issued_at</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e263 ">Time stamp of when the signature was created in milliseconds.</td>

          </tr>
          <tr class="">
            <td data-label="Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e260 ">
              <code>signature</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d4012e263 ">Base64-encoded HMAC-SHA256 signature signed with the
              <code>client_secret</code>. The signature can include the concatenated ID and
              <code>issued_at</code> value, which you can use to verify that the identity
              URL hasn’t changed since the server sent it.
            </td>

          </tr>
        </tbody>
      </table>