Sharing is caring!
Secure Salesforce integration is a necessity for organizations that rely on Salesforce to power customer relationships, automate workflows, and connect enterprise applications. Â
Whether you’re integrating ERP systems, marketing automation platforms, custom applications, or third-party business tools, ensuring secure authentication is the foundation of every successful integration.Â
Salesforce uses OAuth 2.0 Connected Apps to provide secure, token-based authentication without exposing user credentials. Instead of storing usernames and passwords, Connected Apps generate secure access tokens that allow authorized applications to communicate safely with Salesforce APIs. Â
In this guide, you’ll learn how OAuth 2.0 Connected Apps work, why they matter, how to configure them correctly, and the security best practices every organization should follow. You’ll also discover when partnering with an experienced Salesforce consulting partner can help accelerate implementation and ensure your integration aligns with enterprise security standards. Â
Table of ContentsÂ
- What Is a Salesforce Connected App?Â
- Why OAuth 2.0 Matters for Salesforce IntegrationÂ
- How OAuth 2.0 Connected Apps WorkÂ
- Benefits of Using OAuth 2.0 Connected AppsÂ
- Step-by-Step Guide to Configure a Connected AppÂ
- Choosing the Right OAuth FlowÂ
- Salesforce Integration Security Best PracticesÂ
- Common Integration Mistakes to Avoid
How to Use OAuth 2.0 Connected Apps for Secure Salesforce IntegrationÂ
What Is a Salesforce Connected App?Â
A Salesforce Connected App acts as the identity gateway between Salesforce and an external application. It enables third-party systems, mobile applications, middleware platforms, and custom-built software to securely access Salesforce APIs using OAuth 2.0 authentication.Â
 When a Connected App is created, Salesforce generates two important credentials:Â
- Consumer KeyÂ
- Consumer SecretÂ
These credentials uniquely identify the external application during authentication and enable secure communication without sharing user passwords. Connected Apps also allow administrators to configure OAuth scopes, session policies, IP restrictions, refresh token settings, and admin approvals for greater control over API access.Â
Why OAuth 2.0 Matters for Salesforce IntegrationÂ
Traditional integrations often relied on usernames and passwords, creating security vulnerabilities and making credential management difficult. OAuth 2.0 solves these problems by replacing passwords with secure access tokens.Â
Instead of exposing login credentials:Â
- Users authorize applications once. Â
- Salesforce issues secure access tokens. Â
- Applications use these tokens for API requests. Â
- Refresh tokens automatically generate new access tokens when required. Â
This token-based approach significantly reduces the risk of credential theft while providing a secure, scalable authentication framework suitable for enterprise environments.Â
How OAuth 2.0 Connected Apps WorkÂ
The most used authentication mechanism is the Authorization Code (Web Server) Flow. The process follows these steps:Â
Step 1: User Authentication:Â The external application redirects users to Salesforce’s authorization endpoint.Â
Step 2: User Approval:Â The user logs into Salesforce and grants permission to the Connected App.Â
Step 3: Authorization Code: Salesforce redirects the user back to the configured callback URL with a temporary authorization code.Â
Step 4: Token Exchange:Â The application’s backend exchanges the authorization code along with the Consumer Key and Consumer Secret for:Â
- Access Token Â
- Refresh Token Â
Step 5: API Access:Â The application uses the access token to securely access Salesforce APIs.Â
Step 6: Token Refresh:Â When the access token expires, the refresh token obtains a new access token without requiring users to log in again.
Benefits of Using OAuth 2.0 Connected AppsÂ
Organizations choose OAuth 2.0 Connected Apps because they provide multiple advantages:Â
- Enhanced Security:Â No passwords are stored within external applications.Â
- Better Access Control: Administrators define exactly what applications can access using OAuth scopes.Â
- Enterprise Scalability:Â Connected Apps support web applications, mobile apps, middleware, and server-to-server integrations.Â
- Improved Compliance:Â Audit logs, permission policies, and admin approvals simplify compliance with security regulations.Â
- Seamless User Experience: Single Sign-On (SSO) and refresh tokens eliminate repeated authentication.
Step 1:Â Create a Connected App in SalesforceÂ
Step 1.1: Navigate to App Manager – From Salesforce Setup, navigate to Setup → Apps → App Manager, then click New Connected App in the top-right corner.Â
Step 1.2: Fill in Basic Information – Provide the following basic details for your Connected App:Â
- Connected App Name — A descriptive name, such as My Integration App. Â
- API Name — Automatically populated based on the Connected App name. Â
- Contact Email — Required for app management, support, and notifications. Â
Step 1.3: Enable OAuth Settings – Select the Enable OAuth Settings checkbox. This displays the OAuth configuration fields required for authentication.Â
Configure the following:Â
- Callback URL — The redirect URI where your application receives the authorization response after login. This URL must exactly match the redirect URI used in your authorization request. Â
- Selected OAuth Scopes — Move the required permissions into Selected OAuth Scopes, such as: Â
- Manage user data via APIs (api)Â Â
- Perform requests at any time (refresh_token, offline_access) Â
- Access unique user identifiers (openid)Â Â
Step 1.4: Save and ContinueÂ
Click Save. Salesforce displays a notice that the changes may take 2–10 minutes to propagate. This is normal.
Step 2 — Retrieve Your Consumer Key and Consumer SecretÂ
After saving the Connected App, open its detail page and click Manage Consumer Details. You may be prompted to verify your identity.Â
Copy the Consumer Key (your OAuth client_id) & Consumer Secret (your OAuth client_secret). Store the Consumer Secret securely and treat it like a password. Never commit it to source control or expose it in client-side code.
Step 3 — Configure Connected App Policies (Optional but Recommended)Â
Under Manage on the Connected App, you can configure additional security and access policies.Â
- Permitted Users — Select “Admin approved users are pre-authorized” for tighter access control, or “All users may self-authorize” for broader access. Â
- IP Relaxation — Relax IP restrictions if your integration runs from trusted server IP addresses. Â
- Refresh Token Policy — Configure the refresh token expiration policy, such as “Valid until revoked” or “Expire after a specified period of inactivity.”Â
Step 4 — Build the Authorization RequestÂ
From your application, redirect the user’s browser to the authorization endpoint with your client ID, redirect URI, and requested scopes:Â
GETÂ https://login.salesforce.com/services/oauth2/authorizeÂ
 ?response_type=codeÂ
 &client_id=YOUR_CONSUMER_KEYÂ
 &redirect_uri=https://yourapp.com/oauth/callbackÂ
 &scope=api%20refresh_token%20offline_accessÂ
Use https://test.salesforce.com instead of login.salesforce.com if you’re authenticating against a sandbox org.
Step 5 — Exchange the Authorization Code for TokensÂ
Salesforce redirects back to your callback URL with a code parameter. Your backend exchanges it server-side:Â
POSTÂ https://login.salesforce.com/services/oauth2/tokenÂ
Content-Type: application/x-www-form-urlencodedÂ
grant_type=authorization_codeÂ
&code=AUTHORIZATION_CODEÂ
&client_id=YOUR_CONSUMER_KEYÂ
&client_secret=YOUR_CONSUMER_SECRETÂ
&redirect_uri=https://yourapp.com/oauth/callbackÂ
A successful response looks like this:Â
{Â
 “access_token”: “00D…”,Â
 “refresh_token”: “5Aep…”,Â
 “instance_url”: “https://yourorg.my.salesforce.com“,Â
 “id”: “https://login.salesforce.com/id/00D…/005…”,Â
 “token_type”: “Bearer”,Â
 “issued_at”: “1719753600”,Â
 “signature”: “…”Â
}Â
Store the refresh_token securely and associate it with the user/org. The instance_url tells you which Salesforce instance to send future API calls to.
Step 6 — Call the Salesforce REST APIÂ
Use the access token as a Bearer token against the instance URL returned above:Â
GET {instance_url}/services/data/v60.0/sobjects/Account/001XXXXXXXXXXXXÂ
Authorization: Bearer 00D…ACCESS_TOKENÂ
Step 7 — Refresh Expired Access Tokens
Access tokens expire. Use the refresh token to get a new one without re-prompting the user:Â
POSTÂ https://login.salesforce.com/services/oauth2/tokenÂ
Content-Type: application/x-www-form-urlencoded Â
grant_type=refresh_tokenÂ
&client_id=YOUR_CONSUMER_KEYÂ
&client_secret=YOUR_CONSUMER_SECRETÂ
&refresh_token=YOUR_REFRESH_TOKENÂ
Troubleshooting Common ErrorsÂ
 redirect_uri_mismatch – The redirect_uri in your request must match the Callback URL in the Connected App exactly — including trailing slashes and http vs. https. Â
 invalid_client_id – Double check you’re using the Consumer Key (not the Connected App name) and that you copied it without extra whitespace. Â
 invalid_grant – Usually means the authorization code was already used (codes are single-use) or has expired (codes are valid for a few minutes only). Â
 “This app isn’t approved by your org’s admin” Â
 Happens when Permitted Users is set to “Admin approved users are pre-authorized.” Add the user to a permission set tied to the Connected App, or relax the policy for testing.Â
Choosing the Right OAuth FlowÂ
Salesforce supports multiple OAuth 2.0 flows. The most common include:Â
OAuth Flow  | Best For  |
Authorization Code Flow  |          Web applications |
JWT Bearer Flow  |         Server-to-server integrations  |
Client Credentials Flow  |        Machine-to-machine communication  |
Device Flow  |         IoT devices |
User-Agent Flow  |         Browser-based applications  |
Selecting the appropriate flow depends on your application’s architecture and security requirements. Connected Apps support several OAuth flows, including Web Server, JWT Bearer, Device, Client Credentials, and User-Agent flows.Â
Salesforce Integration Security Best PracticesÂ
- Never expose Consumer Secrets in frontend applications. Â
- Always use HTTPS callback URLs. Â
- Apply the principle of least privilege. Â
- Restrict OAuth scopes. Â
- Encrypt refresh tokens. Â
- Rotate Consumer Secrets regularly. Â
- Require admin approval for sensitive integrations. Â
- Monitor Connected App usage. Â
- Review audit logs frequently. Â
- Apply IP restrictions whenever possible.Â
ConclusionÂ
Secure Salesforce integration starts with proper authentication, and OAuth 2.0 Connected Apps provide the trusted framework organizations need to protect sensitive business data while enabling seamless connectivity. By replacing passwords with secure access tokens, applying least-privilege access, and following Salesforce security best practices, businesses can build scalable, reliable, and compliant integrations.Â
Whether you’re connecting a custom application, enterprise middleware, or cloud platform, implementing OAuth 2.0 correctly is critical to long-term success. For organizations managing complex ecosystems, partnering with an experienced Salesforce consulting partner can simplify deployment, reduce security risks, and maximize the value of Salesforce consulting services through proven implementation strategies and ongoing optimization.Â
Frequently Asked Questions (FAQs)
What is a Salesforce Connected App?
A Salesforce Connected App allows external applications to securely access Salesforce using OAuth 2.0 authentication instead of usernames and passwords.Â
Why is OAuth 2.0 important for Salesforce integration?
OAuth 2.0 improves security by using access tokens rather than storing user credentials, making Salesforce integrations safer and more scalable.Â
Which OAuth flow is recommended for web applications?
The Authorization Code (Web Server) Flow is the recommended OAuth flow for most server-side Salesforce web integrations. Â
Can a Salesforce consulting partner help configure Connected Apps?
Yes. An experienced Salesforce consulting partner can configure Connected Apps, implement secure authentication, optimize API access, and ensure enterprise-grade security.Â
What are the benefits of Salesforce consulting services for integrations?
Salesforce consulting services help organizations design secure integration architectures, configure OAuth correctly, improve API performance, maintain compliance, and provide ongoing support.Â
What is the most important OAuth security best practices?
Use HTTPS, encrypt refresh tokens, limit OAuth scopes, rotate Consumer Secrets, require admin approval, and monitor Connected App usage regularly.Â