Skip to content
Docs

Creating a Salesforce OAuth 2.0 app (web server flow)

This guide is part of the Publicus connection catalog. Once you have the credentials, connect the service and Publicus stores them for you.

Distilled from Salesforce’s own documentation: OAuth 2.0 Web Server Flow for Web App Integration, OAuth 2.0 Refresh Token Flow, OAuth Tokens and Scopes, and the OIDC discovery document at https://login.salesforce.com/.well-known/openid-configuration. Retrieved 2026-07-03.

Salesforce calls the OAuth client an external client app (the newer model) or a connected app (the classic model). Either one gives you the Consumer Key (client_id) and Consumer Secret (client_secret) that the web server flow needs.

  1. Sign in to your Salesforce org as an administrator. Enable and configure My Domain (Setup → My Domain) if you have not already — Salesforce recommends authenticating against your My Domain host (MyDomainName.my.salesforce.com).
  2. Create the OAuth client:
    • External client app: Setup → App Manager → New External Client App, or Setup → External Client App Manager. Enable OAuth settings.
    • Connected app (classic): Setup → App Manager → New Connected App, then enable Enable OAuth Settings.
  3. Set the Callback URL to the redirect URI your connection uses. It must match the redirect_uri sent on the authorization request exactly.
  4. Under Selected OAuth Scopes, add the scopes your integration needs. For REST API access with refreshable, long-lived tokens choose:
    • Manage user data via APIs (api) — REST API and Bulk API 2.0 access.
    • Perform requests at any time (refresh_token, offline_access) — required for the web server flow to receive a refresh token.
    • Optionally Access the identity URL service (id, profile, email, address, phone) and openid to enable ID tokens and the /services/oauth2/userinfo verification probe.
  5. (Recommended) Require PKCE: leave “Require Proof Key for Code Exchange (PKCE)” enabled. On the authorization request send code_challenge (the base64url-encoded SHA256 hash of a code_verifier); on the token request send the matching code_verifier (128 bytes of high-entropy random data, base64url-encoded).
  6. Save. Open Manage Consumer Details to copy the Consumer Key (client_id) and Consumer Secret (client_secret). You may be prompted to verify your identity first.
  7. Choose the login host for the connection:
    • Production / Developer Edition: login.salesforce.com
    • Sandbox: test.salesforce.com
    • Or your org’s My Domain: MyDomainName.my.salesforce.com
  8. Authorization request — redirect the user to https://{login_host}/services/oauth2/authorize?response_type=code&client_id=...&redirect_uri=... (plus scope, and code_challenge/code_challenge_method=S256 when using PKCE). After the user logs in and approves, Salesforce redirects back to the callback URL with a code.
  9. Token request — POST the code to https://{login_host}/services/oauth2/token as application/x-www-form-urlencoded with grant_type=authorization_code, code, client_id, client_secret, redirect_uri (and code_verifier if PKCE was used). The JSON response returns access_token, refresh_token (only when the refresh_token/offline_access scope was granted), instance_url, id, scope, token_type (Bearer), issued_at, and signature. There is no expires_in — the access-token lifetime is governed by the org’s session settings.
  10. Make API calls against the instance_url from the token response, e.g. GET {instance_url}/services/data/. Send the token as Authorization: Bearer {access_token}.
  11. Refresh — when the access token expires, POST grant_type=refresh_token, refresh_token, client_id, client_secret to the same token endpoint. The response returns a new access_token (and a fresh instance_url) but no new refresh_token: the original refresh token remains valid until revoked or until the app’s refresh-token policy expires it.

Open Connections under Credentials, choose Salesforce, and pick Salesforce OAuth 2.0 (web server flow). Publicus asks for exactly the fields listed above and keeps them in your workspace’s secret storage.

See also: Salesforce in the catalog.

This guide is maintained by Publicus and published under CC BY 4.0.