Commit e66053e
committed
Port upstream forcedotcom#4087: centralized token-refresh coordinator (unit 44)
Semantic re-implementation of forcedotcom/dev 6e09678 (merge of
bbirman/refreshCoordinator) onto the ObjC→Swift migration branch.
WHAT: introduces SFSDKTokenRefreshCoordinator — a process-wide singleton that
coalesces concurrent token-refresh requests per credential (keyed by
credentials.identifier) so at most one refresh is in-flight at a time. This
prevents the double-spend race with single-use (rotating) refresh tokens, where
concurrent refreshes would invalidate each other's tokens. Callbacks are
delivered on the main queue; background-task protection wraps the refresh.
MIGRATION NOTES (no new ObjC; compiled path is Swift):
- NEW SFSDKTokenRefreshCoordinator.swift (upstream added .h/.m ObjC) —
@objc singleton, wired into pbxproj (framework Sources + Headers-free).
NEW SFSDKTokenRefreshCoordinatorTests.swift (upstream .m, +602) ported to
Swift and wired to the test target.
- SFRestAPI.swift / SFIdentityCoordinator.swift / SFUserAccountManager.swift /
UserAccountManager.swift (async refresh) / SFSDKOAuth2.swift /
SFSDKTestRequestListener.swift: the compiled Swift twins carry the behavior
change (route through the coordinator; SFRestAPI: sessionRefreshInProgress +
pendingRequestsBeingProcessed + oauthSessionRefresher collapse to a single
refreshCycleActive flag; cleanup now delivers "User logged out" and cancels
in-flight tasks; OAuth2 completion no longer double-hops main queue;
TestRequestListener spins the run loop instead of a semaphore to avoid a
main-thread deadlock now that the coordinator delivers on main).
- WebSocketClient.swift: TokenRefreshCoordinator actor renamed
WebSocketReconnectCoordinator (it only gates reconnection; token dedup now
lives in SFSDKTokenRefreshCoordinator).
- Public-API deprecation of SFOAuthSessionRefresher (14.0→15.0): expressed on
the Swift members consumers call (@available deprecated), with non-deprecated
internal seams (init(internalCredentials:) / refreshSessionInternal) that the
coordinator, tests, and mock use so the SDK's own paths stay warning-free —
mirrors the unit-39 forceAdvancedAuthenticationInternal precedent. Upstream's
ObjC SFSDK_DEPRECATED lives on tombstoned headers, so it has no compiled home.
- De-referenced .m/.h mirrors (SFRestAPI.m, SFIdentityCoordinator.m,
SFSDKOAuth2.m, SFSDKTestRequestListener.m, SFOAuthSessionRefresher.m/.h and
the two test .m) ref-synced to the upstream post-image on top of the migrated
pre-image (keeping the migration's @import/-Swift.h deltas); tombstone headers
skipped; SFUserAccountManager.m had nothing to sync (refreshCredentials lives
in the .swift twin).
ESCALATION (flag for human PR review): OAuth/token-refresh control flow +
public-API deprecation (SFOAuthSessionRefresher). This is the live-auth
unblocker for Phase 2.
Gate: SDKCore/SmartStore/MobileSync build-for-testing all GREEN, 0 new
warnings; 22 targeted tests pass (11 coordinator + 7 data-task-race + 4
refresher). Live-org auth-util end-to-end tests remain XCTSkip-gated (Phase 2).
Upstream: 6e09678 (PR forcedotcom#4087) · marker unit 44 · __U44__1 parent 9f7b84f commit e66053e
23 files changed
Lines changed: 1424 additions & 246 deletions
File tree
- .claude
- libs/SalesforceSDKCore
- SalesforceSDKCore.xcodeproj
- SalesforceSDKCoreTests
- SalesforceSDKCore/Classes
- Extensions
- Identity
- OAuth
- RestAPI
- Test
- UserAccount
- Util
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
| |||
658 | 660 | | |
659 | 661 | | |
660 | 662 | | |
| 663 | + | |
| 664 | + | |
661 | 665 | | |
662 | 666 | | |
663 | 667 | | |
| |||
1269 | 1273 | | |
1270 | 1274 | | |
1271 | 1275 | | |
| 1276 | + | |
1272 | 1277 | | |
1273 | 1278 | | |
1274 | 1279 | | |
| |||
1421 | 1426 | | |
1422 | 1427 | | |
1423 | 1428 | | |
| 1429 | + | |
1424 | 1430 | | |
1425 | 1431 | | |
1426 | 1432 | | |
| |||
2538 | 2544 | | |
2539 | 2545 | | |
2540 | 2546 | | |
| 2547 | + | |
2541 | 2548 | | |
2542 | 2549 | | |
2543 | 2550 | | |
| |||
2661 | 2668 | | |
2662 | 2669 | | |
2663 | 2670 | | |
| 2671 | + | |
2664 | 2672 | | |
2665 | 2673 | | |
2666 | 2674 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
92 | 104 | | |
93 | 105 | | |
94 | 106 | | |
| |||
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
171 | 170 | | |
172 | 171 | | |
173 | 172 | | |
174 | | - | |
175 | | - | |
| 173 | + | |
176 | 174 | | |
177 | 175 | | |
178 | 176 | | |
| |||
221 | 219 | | |
222 | 220 | | |
223 | 221 | | |
224 | | - | |
225 | 222 | | |
226 | 223 | | |
227 | 224 | | |
228 | 225 | | |
229 | 226 | | |
230 | 227 | | |
231 | 228 | | |
232 | | - | |
233 | 229 | | |
234 | 230 | | |
235 | 231 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
| |||
173 | 172 | | |
174 | 173 | | |
175 | 174 | | |
176 | | - | |
177 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
178 | 180 | | |
179 | 181 | | |
180 | 182 | | |
| |||
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
220 | | - | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| |||
0 commit comments