Sub topic 2
What a connected app is and what it does
This chapter assumes you know basic Salesforce administration (Setup, profiles, permission sets), can read an HTTP request, and understand the difference between authentication and authorization. Later chapters cover the OAuth settings, flows, and policies in detail. This one explains what the connected app is and which parts of it do which job.
The role of a connected app
A connected app is a Salesforce configuration record that registers an external application with your org. The external application can be a mobile app, a web service, a CI pipeline, or a third-party SaaS product. The record tells Salesforce three things:
- Identity: which application is calling, using a consumer key.
- Permission: which access the application may request, using OAuth scopes.
- Rules: who may use the application and under what conditions, using policies.
Without this registration, Salesforce has no way to recognize the caller. It also has no place to enforce rules such as session length or IP ranges. A username and password sent straight to the API carries none of that control.
A connected app is not a credential. It is the definition of a client. Users or integration users still authenticate, and the connected app decides whether this client may act on their behalf.
What a connected app can contain
A connected app is a bundle of optional capabilities. You enable only what the integration needs.
| Capability | What it does | Typical use |
|---|---|---|
| OAuth settings | Issues a consumer key and secret, defines callback URLs and scopes, and enables flows | API integrations, mobile apps, CLI tools |
| SAML single sign-on | Lets Salesforce act as an identity provider for the app | Signing users in to a third-party web app |
| Canvas | Embeds an external web app inside Salesforce | Third-party UI shown in a tab or page |
| Mobile policies | Requires a PIN or restricts access on mobile devices | Mobile apps built with the Mobile SDK |
| Custom connected app handler | Runs Apex when the app is used | Custom checks at token issuance |
Most integrations use only the OAuth settings. SAML is covered in its own chapter later in the series.
Where the pieces live
Setup shows a connected app in two places, and the split matters.
- App Manager: you create and edit the definition here. It holds the OAuth settings, scopes, callback URL, and certificate.
- Manage Connected Apps (Connected Apps OAuth Usage and the installed-app list): you set the policies here. These are the permitted users, IP relaxation, refresh token policy, and session timeout.
A connected app created through OAuth settings is automatically installed in the org that owns it. In other orgs it must be installed first, for example by a package. Salesforce also restricts users from authorizing a connected app that is not installed unless an admin has allowed it. This blocks a user from granting a hostile app access with a single click. If a user reports an "app is not installed" or "approval required" style error, check this first.
The next table shows what the connected app stores about the client, and what it leaves to the user and the org.
| Item | Owned by | Notes |
|---|---|---|
| Consumer key | Connected app | Public identifier of the client, sent as `client_id` |
| Consumer secret | Connected app | Confidential. Not every flow needs it |
| Callback URL | Connected app | Must match the `redirect_uri` exactly |
| Scopes | Connected app | The upper limit on what tokens can do |
| User permissions | Profile and permission sets | A token never exceeds the user's own access |
How the connected app fits into a request
Two separate checks apply. The connected app decides whether this client may get a token, and with which scopes. The user's profile and permission sets then decide what that token can do. A token with the api scope for a user who lacks access to the Account object still cannot read accounts.
Verifying that a token works
Once an integration has obtained an access token, you can test it against the REST API versions resource. The call needs no object permissions, so it separates token problems from permission problems.
curl https://MyDomain.my.salesforce.com/services/data/ \
-H "Authorization: Bearer $ACCESS_TOKEN"A successful call returns a JSON list of API versions. An INVALID_SESSION_ID error means the token is expired, revoked, or was issued for a different org or My Domain.
Common errors when starting out
- Using the new key too soon. A newly saved consumer key can take a few minutes to work. Early requests may fail with an invalid client identifier error.
- Callback URL mismatch. The
redirect_uriin the request must match a registered callback URL exactly, including scheme, path, and trailing slash. - Requesting scopes the app does not allow. Scopes in the request cannot exceed those selected on the connected app.
- Granting the secret to public clients. Mobile and single-page apps cannot keep a secret. Use a flow that does not depend on one.
- Assuming the connected app grants data access. It does not. Data access always comes from the user's permissions.
Connected apps and the move to external client apps
The connected app model mixes two audiences in one record. The developer who builds the app and the admin who governs it edit the same record, and the record is awkward to package and move between orgs. Salesforce introduced external client apps (ECAs) to separate these concerns, and it now steers new integrations toward them. Depending on your release and org settings, creating new connected apps may be limited or off by default. You will still meet connected apps in existing orgs, in packages, and in third-party products, so you need to read and secure them. The ECA chapters later in this tutorial build directly on the vocabulary introduced here.
Exercise
An integration user has the api scope on a connected app but receives "insufficient access" when querying Opportunities. Which two places do you check, and why is the connected app probably not the cause?
Show answer
Check the integration user's profile and permission sets for object and field access on Opportunity, and check the sharing settings that control record visibility. A connected app only limits what the client may request (scopes) and who may use it (policies). A token can never exceed the user's own permissions. The token was issued, so the connected app allowed the request, and the missing access comes from the user.
Exercise
Name the two Setup areas where you configure a connected app, and give one setting that belongs in each.
Show answer
App Manager holds the definition, such as the callback URL, scopes, or certificate. Manage Connected Apps holds the policies, such as permitted users, IP relaxation, refresh token policy, or session timeout.