What role do Connected App security policies play in governing token lifecycles and session invalidation?
Answer
Basics: When an external app uses OAuth, Salesforce issues an access token (short-lived session) and optionally a refresh token (long-lived). Policies set on the connected app decide how long these remain valid and who can obtain them.
How it works: Setup > App Manager > app > Manage > Edit Policies:
- Permitted Users: "All users may self-authorize" or "Admin-approved users are pre-authorized" (then assign profiles/permission sets).
- IP Relaxation: enforce IP restrictions, relax IP restrictions, or relax for activated devices.
- Refresh Token Policy: valid until revoked, immediately expire, expire after a time period, or expire if not used for a period.
- Session Policies: timeout value (the access token lifetime follows the session timeout) and high-assurance requirement.
- Revoke: Setup > OAuth Connections Usage, a user's detail page, or the OAuth revoke endpoint.
Advanced / deep dive: The access token's validity is tied to the session timeout, not a separate JWT exp you can set freely. Use JWT bearer flow for server-to-server with pre-authorized users, and short refresh token policies for high-risk apps. Without the "Refresh token valid until revoked" choice, offline access stops after expiry. Revoking a refresh token kills future access-token issuance but an existing access token lives until its session expires, so also use "Revoke" session-level actions and Login History/Session Management. Salesforce has been steering new development toward External Client Apps as the successor (creation of new connected apps may be restricted by default in recent releases; verify current state). Combine with MFA, IP ranges, and Event Monitoring to detect token abuse. Scopes (api, refresh_token, ) should be minimal.