# What role do Connected App security policies play in governing token lifecycles and session invalidation?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Connected Apps, Security Policies

Read it on the site: https://www.forcechallenges.com/interview-questions/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:
1. **Permitted Users**: "All users may self-authorize" or "Admin-approved users are pre-authorized" (then assign profiles/permission sets).
2. **IP Relaxation**: enforce IP restrictions, relax IP restrictions, or relax for activated devices.
3. **Refresh Token Policy**: valid until revoked, immediately expire, expire after a time period, or expire if not used for a period.
4. **Session Policies**: timeout value (the access token lifetime follows the session timeout) and high-assurance requirement.
5. 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`, `full`) should be minimal.

**Code / config example:**
```text
Revoke refresh/access token (RFC 7009 style endpoint):
POST https://login.salesforce.com/services/oauth2/revoke
Content-Type: application/x-www-form-urlencoded

token=<refresh_or_access_token>
```

**Hidden gotchas & must-remember points:**
- Pre-authorized mode blocks any user not granted via profile/permission set.
- Enforced IP restrictions follow the connected app, overriding user profile IP relaxation behavior.
- Access token lifetime equals the session timeout.
- A revoked refresh token does not instantly kill an already issued access token.
- "Valid until revoked" is convenient but risky for sensitive apps.
- Connected app changes can take a few minutes to propagate.

**Best practice:** Use admin-approved users, enforced IPs, short refresh lifetimes and minimal scopes, and review OAuth usage regularly.

---
Source: ForceChallenges · last updated 2026-11-02
