Sub topic 9
Policies: permitted users, IP relaxation, and refresh tokens
This chapter covers the three policies that decide who can use a connected app, from where, and for how long. It assumes you can navigate Setup, know how profiles and permission sets work, and have already configured the OAuth settings and flow for an app. OAuth settings define how an app asks for access. Policies define what the org allows.
Where policies live
Open Setup, go to Manage Connected Apps, select the app, and click Edit Policies. Three groups of settings matter here:
- Permitted Users controls who can authorize the app.
- IP Relaxation controls whether IP restrictions apply to the app's sessions.
- Refresh Token Policy controls how long a refresh token stays valid.
Policies belong to the org that installs the app, not to the developer who built it. The same app can be strict in your production org and loose in a scratch org.
Permitted users
This setting has two values.
| Value | Behavior | Typical use |
|---|---|---|
| All users may self-authorize | Any user can approve the app on the consent screen, subject to the app's OAuth scopes. | Low-risk tools, developer testing |
| Admin approved users are pre-authorized | Only users whose profile or permission set is assigned to the app can get tokens. No consent screen is shown. | Production integrations, anything with broad scopes |
With admin approval, you assign access in the app's Profiles and Permission Sets related lists. A user who is not covered gets an error such as user is not admin approved to access this app, and the app receives no token.
Some details trip people up:
- Switching from self-authorize to admin approved does not grant anyone access. Users who authorized earlier but are not covered by an assigned profile or permission set lose access. Assign the profiles or permission sets first, then change the setting.
- The JWT bearer flow needs pre-authorization, because no consent screen exists in that flow. Set the app to admin approved and assign the integration user's profile or a permission set.
- Assigning a permission set to the app does not give a user the object permissions they need. It only lets that user obtain a token. The token still carries only what the user can do in Salesforce, limited by the scopes.
IP relaxation
IP relaxation decides whether the org's IP controls apply to sessions the app creates. Those controls are the profile's login IP ranges and the org's trusted IP ranges in Network Access.
| Value | Effect |
|---|---|
| Enforce IP restrictions | Login IP ranges on the profile apply, and logins from untrusted IPs may be challenged. This is the default and the safest choice. |
| Relax IP restrictions with second factor | Users outside the allowed range can proceed if they complete a second factor. |
| Relax IP restrictions | The app can connect from any IP, so profile login IP ranges do not block it. |
Reach for relaxation only when you cannot control the caller's address. Examples are a SaaS vendor's changing egress IPs, or a mobile client. Relaxing IP restrictions removes a layer of defense, so for a server integration with stable addresses, keep Enforce IP restrictions and add those addresses to the integration profile's login IP ranges.
Refresh token policy
An access token is short-lived. A refresh token lets the app get new access tokens without sending the user through login again. The app receives a refresh token only if it requested the refresh_token (or offline_access) scope and the policy allows it.
| Policy | Meaning |
|---|---|
| Refresh token is valid until revoked | The token works until a user or admin revokes it. This is the default. |
| Immediately expire refresh token | The token expires as soon as it is issued, so the app effectively works only for the current session. |
| Expire refresh token if not used for N | The token expires after N days, hours, or minutes without use. Each use resets the clock. |
| Expire refresh token after N | The token expires a fixed time after issue, even if used constantly. |
Choosing between the two timed options is a real design decision. An idle timeout suits an interactive app that people use regularly. A fixed expiry forces re-authorization on a schedule, which suits sensitive data. A fixed expiry also means any unattended integration will stop working at that time unless it can re-authenticate by itself.
This request redeems a refresh token for a new access token:
curl -X POST https://MyDomain.my.salesforce.com/services/oauth2/token \
-d grant_type=refresh_token \
-d client_id="$CONSUMER_KEY" \
-d refresh_token="$REFRESH_TOKEN"A successful response contains a new access_token. Salesforce normally does not return a new refresh token, so keep using the original one. If the policy has expired it, the call fails with invalid_grant.
An admin or user can end access immediately by revoking the token:
curl -X POST https://MyDomain.my.salesforce.com/services/oauth2/revoke \
-d token="$REFRESH_TOKEN"Revoking a refresh token also invalidates access tokens issued from it.
Related session settings
The same edit page has settings that interact with these policies:
- Timeout Value sets how long an access token's session stays valid when idle. A short value limits the damage from a leaked access token.
- Require secret for Web Server Flow and Require secret for Refresh Token Flow make the consumer secret mandatory when redeeming codes or refresh tokens. Keep them on for apps that can protect a secret.
- High assurance session required forces users to have completed multi-factor authentication for the session.
Putting it together
A reasonable baseline for a production integration:
- Set Permitted Users to admin approved, and assign one permission set to the dedicated integration user.
- Leave IP Relaxation on enforce, and list the caller's static IPs in the integration profile's login IP ranges.
- Choose a timed refresh token policy that matches how often the integration runs.
- Request only the scopes you need.
Exercise
A nightly integration uses the JWT bearer flow and starts failing with "user is not admin approved to access this app" right after an admin changed Permitted Users to "Admin approved users are pre-authorized". What is the likely cause, and how do you fix it without relaxing any other policy?
Show answer
The integration user's profile and permission sets are not assigned to the app, so the user is no longer authorized. In the connected app's Profiles or Permission Sets list, add the integration user's profile or a permission set assigned to that user. No IP or refresh token policy needs to change.
Exercise
An interactive app is used every weekday, and the security team wants users to re-authenticate at least every 30 days. Which refresh token policy fits, and why?
Show answer
"Expire refresh token after 30 days". It is a fixed lifetime from issue, so constant use cannot extend it. An idle-based policy would let a token live forever as long as it is used within the idle window.