Sub topic 9
Policies: permitted users, IP relaxation, and refresh tokens
This chapter assumes you know what a connected app is, how its OAuth settings (consumer key, secret, callback URL) work, and how scopes and flows differ. Policies are the admin-side rules that decide who may use the app, from where, and for how long.
Where policies live
OAuth settings describe what the app asks for. Policies describe what your org allows. In Setup, open Manage Connected Apps, then choose Edit Policies on the app. Policies apply to every user and every flow that uses the app.
Permitted users
This setting controls who can obtain a token.
| Value | Behavior |
|---|---|
| All users may self-authorize | Any user in the org can approve the app on first use. |
| Admin approved users are pre-authorized | Only users in assigned profiles or permission sets can use it. Others get an error. |
Choose the second value for anything that touches sensitive data. You then assign profiles or permission sets to the app. The next chapter covers that step.
IP relaxation
IP relaxation decides whether the user's login IP restrictions apply to OAuth logins.
- Enforce IP restrictions applies the profile's login IP ranges and the org's trusted IP ranges.
- Relax IP restrictions with second factor skips IP checks if the user completes multi-factor authentication.
- Relax IP restrictions skips IP checks entirely.
Server-to-server integrations often run from changing cloud addresses, so teams are tempted to relax IP rules. A safer approach is to keep enforcement on and add the known egress addresses to the integration user's profile.
Refresh token policy
A refresh token lets an app get new access tokens without asking the user to log in again. The policy sets how long that ability lasts.
- Refresh token is valid until revoked is the default. It never expires on its own.
- Immediately expire refresh token means the app gets no usable refresh token.
- Expire refresh token if not used for N expires it after a period of inactivity.
- Expire refresh token after N sets a fixed lifetime.
Your app must also request the refresh_token scope (or offline_access) in its OAuth settings. If the scope is missing, the policy has nothing to apply to.
Session timeout
The Timeout Value sets how long an access token's session stays valid without activity. After it expires, the app uses its refresh token to get a new one.
Testing a policy change
After you change a policy, confirm the behavior with a real token request. Refresh an access token like this:
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 reply contains a new access_token. An invalid_grant reply means the refresh token has expired or been revoked.
Exercise
An integration runs from a cloud service whose IP address changes often. The security team wants to avoid the "Relax IP restrictions" setting. What is a safer option, and which Permitted Users value should you pair it with?
Show answer
Keep "Enforce IP restrictions" and add the service's known egress address ranges to the integration user's profile login IP ranges. Pair it with "Admin approved users are pre-authorized" so only the assigned profile or permission set can use the app.