Sub topic 10
Controlling access with profiles and permission sets
This chapter assumes you know how to assign profiles and permission sets in Setup. It also assumes you have seen the OAuth settings and policies of a connected app. You should be able to send a token request with curl.
OAuth scopes limit what an app may ask for. Profiles and permission sets decide which users may use the app at all. This chapter covers how the two fit together and how they affect the JWT bearer and client credentials flows.
Two layers of access
Every API call made with an access token passes two checks:
- App-level check. Is this user allowed to use this app? Policies and profile or permission set assignments answer this.
- User-level check. Does this user have the object, field, and system permissions for the request? The usual sharing and permission model answers this.
The OAuth scope is a ceiling on top of both checks. A token with only the api scope cannot use the Web browser UI, even if the user is a System Administrator. A token with every scope still cannot read an object the user cannot read. The app never receives more than the user has, and never more than the scopes allow.
The Permitted Users policy
The Permitted Users policy controls how users get access:
- All users may self-authorize. Any user who can log in may approve the app on first use. No profile or permission set assignment is needed.
- Admin approved users are pre-authorized. Only users who hold the app through a profile or permission set can use it. Everyone else is refused.
Choose admin approval for any integration that touches sensitive data. Self-authorization suits low-risk tools where each user decides for themselves.
Switching from self-authorize to admin approved takes effect immediately for existing users. Tokens that were issued to users without an assignment are revoked. Assign the app to the right users before you change the policy, or you will break working integrations.
Assigning the app
With admin approval, you assign the app to users in one of two ways:
- Profiles. Every user with the profile gets access. This is coarse, and a profile cannot be combined with others.
- Permission sets. Only users who hold the permission set get access. You can grant it to some users and revoke it for others.
Prefer permission sets. Create one set per integration or per audience, for example Sales_Dashboard_App_Access. You can then add and remove people without editing profiles. You can also see in one place who can use the app.
In a connected app, open Manage Connected Apps, open the app, and use the Profiles and Permission Sets related lists. For an external client app (ECA), assignment lives in the app's policies. Check the current Setup page for the exact layout, because Salesforce changes it between releases.
A permission set that grants app access does not grant data access. Pair it with a separate permission set for the objects and fields the integration needs, so each can change on its own.
Required user permissions
An integration user typically needs these:
| Permission | Why it matters |
|---|---|
| API Enabled | Required for REST and SOAP API calls. Without it, calls fail with an API-disabled error. |
| Object and field permissions | Decide which records the token can read or write. |
| Use Any API Client | Needed only if your org restricts uninstalled or unapproved apps through API Access Control. |
If your org turns on the API Access Control setting, apps that are not installed and admin approved are blocked for users who lack Use Any API Client. Treat that permission as a break-glass option, not a default.
Effect on non-interactive flows
Both server-to-server flows have no user at the keyboard to click Allow. Pre-authorization is therefore the key setup step.
JWT bearer. The user in the sub claim must be pre-authorized. Set Permitted Users to admin approved and assign the user's profile or a permission set. If you skip this, the token endpoint returns an error like this one:
{
"error": "invalid_grant",
"error_description": "user hasn't approved this consumer"
}An invalid_grant response with an approval message points at access control, not at your signing key. Check the policy and assignments before you regenerate certificates.
Client credentials. The app has a single run-as user, set in its policies. That user needs the app assigned, the API Enabled permission, and the data access the integration requires. Every call runs as that user, so any permission you give the user is available to anyone holding the consumer secret. Use a dedicated integration user, not a named employee, and give it only what the integration needs.
Auditing who has access
You can query which profiles and permission sets hold an app. First find the app ID, then list the assignments:
sf data query --target-org ci-org \
--query "SELECT Id, Name FROM ConnectedApplication WHERE Name = 'Sales Dashboard'"
sf data query --target-org ci-org \
--query "SELECT Parent.Label, Parent.IsOwnedByProfile FROM SetupEntityAccess WHERE SetupEntityType = 'ConnectedApplication' AND SetupEntityId = '<ID from the first query>'"Each row is one assignment. A permission set tied to a profile has IsOwnedByProfile set to true. Review this list when people change roles, and after a migration to an ECA.
To give a user a permission set from the command line:
sf org assign permset \
--name Sales_Dashboard_App_Access \
--on-behalf-of [email protected] \
--target-org ci-orgCommon mistakes
- Changing the policy first. Switching to admin approved before assigning anyone revokes tokens for everyone.
- Granting the app but not API Enabled. The token is issued, then every API call fails.
- Using a named employee as the run-as or JWT user. The integration breaks when that person leaves or changes roles.
- Treating the scope as the permission. The
fullscope does not bypass the user's permissions, and a narrow scope does not reduce them. Both limits apply. - Assigning access through a broad profile. Too many users get the app. A permission set gives finer control.
Exercise
A JWT bearer request for [email protected] returns invalid_grant with the message "user hasn't approved this consumer". The signing key and certificate are correct. What do you check, and what do you change?
Show answer
Check the app's Permitted Users policy. If it is set to self-authorize, the user never approved the app, and a JWT flow cannot ask them to. Set the policy to "Admin approved users are pre-authorized". Assign the app to the user through a permission set (preferred) or profile, and give the user the API Enabled permission. Assign before switching the policy so other users keep working. Then retry the request.
Exercise
Why can a token with the full scope still fail to read an Account record?
Show answer
Scopes only set a ceiling on what the app may ask for. The request is also checked against the user's own permissions, including object, field, and sharing access. If the user cannot read the Account, the token cannot either.