# What role do Connected Apps play in establishing secure OAuth authentication frameworks with Salesforce?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Connected Apps, OAuth Security

Read it on the site: https://www.forcechallenges.com/interview-questions/what-role-do-connected-apps-play-in-establishing-secure-oauth-authentication-frameworks-with-salesforce

## Answer

**Basics:** Without registration, Salesforce cannot know which client is asking for access or what it may do. A Connected App provides the OAuth client ID and secret, lets admins approve or block the app, and ties tokens to policy. Note on direction: Salesforce is moving new integrations to **External Client Apps** and has restricted creation of new Connected Apps in newer releases; verify the current status in release notes. Existing Connected Apps continue to work.

**How it works:**
1. Setup > App Manager > New Connected App (or an External Client App).
2. Enable OAuth Settings, set the callback URL and select scopes (`api`, `refresh_token`/offline access, `openid`, `web`, `full` and more).
3. Salesforce generates the **Consumer Key** and **Consumer Secret**.
4. Manage policies under Manage Connected Apps: **Permitted Users** (all users may self-authorize, or admin-approved users are pre-authorized through profiles and permission sets), **IP Relaxation**, **Refresh Token Policy**, session timeout, high assurance.
5. The client runs an OAuth flow and receives an access token (and refresh token if allowed).
6. Admins can revoke tokens and monitor usage via OAuth Usage.

**Advanced / deep dive:** Choose the flow to match the client: Web Server (with PKCE) for server apps, JWT Bearer for server-to-server with a certificate, Client Credentials for headless integrations tied to a run-as user, Device flow for devices. Use admin-approved pre-authorization plus permission sets to restrict who can use an integration. Scopes limit API surface (for example, `api` but not `full`). A dedicated integration user with minimal permissions is the standard pattern; scopes limit access further but never exceed the user's permissions. Connected Apps also support SAML SSO and can be packaged in managed packages (installed copies enforce subscriber policies).

**Code / config example:** Token request for a Client Credentials flow:
```
POST https://MyDomain.my.salesforce.com/services/oauth2/token
grant_type=client_credentials&client_id=<KEY>&client_secret=<SECRET>
```

**Hidden gotchas & must-remember points:**
- A new Connected App can take a few minutes (up to about 10) before it works.
- "IP Relaxation: Enforce IP restrictions" is the default behavior and can silently block remote servers.
- Scopes cannot grant more than the user's permissions.
- Refresh token policy defaults can cause tokens to expire sooner than expected.
- Use the My Domain URL, not `login.salesforce.com`, in modern setups.
- Verify the External Client App migration guidance for new builds.

**Best practice:** Use a least-privilege integration user, admin-approved access, narrow scopes, IP restrictions where static IPs exist, and rotate secrets.

---
Source: ForceChallenges · last updated 2026-11-02
