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.
- 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). - 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.
- Set the Callback URL to the redirect URI your connection uses. It must match the
redirect_urisent on the authorization request exactly. - 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) andopenidto enable ID tokens and the/services/oauth2/userinfoverification probe.
- Manage user data via APIs (
- (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 acode_verifier); on the token request send the matchingcode_verifier(128 bytes of high-entropy random data, base64url-encoded). - 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. - 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
- Production / Developer Edition:
- Authorization request — redirect the user to
https://{login_host}/services/oauth2/authorize?response_type=code&client_id=...&redirect_uri=...(plusscope, andcode_challenge/code_challenge_method=S256when using PKCE). After the user logs in and approves, Salesforce redirects back to the callback URL with acode. - Token request — POST the code to
https://{login_host}/services/oauth2/tokenasapplication/x-www-form-urlencodedwithgrant_type=authorization_code,code,client_id,client_secret,redirect_uri(andcode_verifierif PKCE was used). The JSON response returnsaccess_token,refresh_token(only when therefresh_token/offline_accessscope was granted),instance_url,id,scope,token_type(Bearer),issued_at, andsignature. There is noexpires_in— the access-token lifetime is governed by the org’s session settings. - Make API calls against the
instance_urlfrom the token response, e.g.GET {instance_url}/services/data/. Send the token asAuthorization: Bearer {access_token}. - Refresh — when the access token expires, POST
grant_type=refresh_token,refresh_token,client_id,client_secretto the same token endpoint. The response returns a newaccess_token(and a freshinstance_url) but no newrefresh_token: the original refresh token remains valid until revoked or until the app’s refresh-token policy expires it.
Connect it to Publicus
Section titled “Connect it to Publicus”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.