Skip to content

fix: clear retained account data after SSO identity change - WPB-27416 - #5229

Open
netbe wants to merge 2 commits into
developfrom
fix/multi-ingress-WPB-27416
Open

netbe wants to merge 2 commits into
developfrom
fix/multi-ingress-WPB-27416

Conversation

@netbe

@netbe netbe commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator
TaskWPB-27416 [iOS] Clear retained account data when logging in with a different SSO identity

Issue

This re-applies changes that were reverted for multi-ingress. All this code in the following commit has been reviewed and approved:

commit 8e40f1b.

It will also include a fix for the case that failed QA previously: a different IdP ID displays the confirmation dialog. A dedicated PR will be done for that.

Testing

N/A


Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Make sure you use the API for UI elements that support large fonts.
  • All colors are taken from WireDesign.ColorTheme or constructed using WireDesign.BaseColorPalette.
  • New UI elements have Accessibility strings for VoiceOver.

…change - WPB-27416 (#5086)" - WPB-27416 🍒 (#5160)"

This reverts commit 8e40f1b.
Copilot AI lite review requested due to automatic review settings September 14, 2026 13:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved session cleanup risks can cause missed identity-change handling, concurrent data deletion, and incomplete cleanup.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds SSO identity tracking and clears retained account data when the identity provider changes.

Changes:

  • Persists and propagates SSO identity-provider IDs.
  • Adds identity-change confirmation, purge, and restart flows.
  • Updates account/session models and related tests.
File summaries
File Summary
WireDomain/Tests/WireDomainTests/Account/AccountStoreTests.swift Tests provider-ID persistence.
WireDomain/Tests/WireDomainTests/Account/AccountManagerTests.swift Tests account updates.
WireDomain/Sources/WireDomain/Account/StoredAccount.swift Stores provider ID metadata.
WireAuthentication/Tests/WireAuthenticationUITests/Views/DetermineAuthMethod/DetermineAuthMethodViewModelTests.swift Tests provider-ID propagation.
WireAuthentication/Tests/WireAuthenticationLogicTests/DetermineAuthMethodUseCaseTests.swift Tests SSO discovery metadata.
WireAuthentication/Sources/WireAuthenticationUI/Views/DetermineAuthMethod/DetermineAuthMethodViewModel.swift Carries identity metadata through login.
WireAuthentication/Sources/WireAuthenticationLogic/DetermineAuthMethodUseCase.swift Associates SSO codes with provider IDs.
WireAuthentication/Sources/WireAuthenticationAPI/Use cases/DetermineAuthMethodUseCaseProtocol.swift Extends SSO method data.
WireAuthentication/Sources/WireAuthenticationAPI/Models/AuthenticationResult.swift Adds provider-ID metadata.
WireAuthentication/Sources/WireAuthentication/WireAuthenticationAssembly.swift Updates authentication callbacks.
WireAuthentication/Sources/WireAuthentication/Components/RootComponent.swift Propagates callback changes.
WireAuthentication/Sources/WireAuthentication/Components/DetermineAuthMethodComponent.swift Updates component dependencies.
wire-ios/Wire-iOS/Sources/Authentication/Helpers/ObservableSessionManager.swift Exposes retained-data purging.
wire-ios/Wire-iOS/Sources/Authentication/Event Handlers/AuthenticationCoordinatorAction.swift Adds purge and restart actions.
wire-ios/Wire-iOS/Sources/Authentication/Coordinator/AuthenticationCoordinator.swift Handles identity changes and cleanup.
wire-ios/Wire-iOS/Sources/Authentication/AuthenticationInterfaceBuilder.swift Determines active accounts.
wire-ios-sync-engine/Tests/Source/UserSession/UnauthenticatedSessionTests.swift Tests provider-ID storage.
wire-ios-sync-engine/Source/UnauthenticatedSession/UnauthenticatedSession.swift Stores provider IDs on new accounts.
wire-ios-sync-engine/Source/SessionManager/SessionManager.swift Implements retained-data cleanup. Findings include active-session detection, concurrent deletion, cookie-removal error handling, and missing purge coverage.
wire-ios-data-model/Source/Model/Account/Account.swift Adds persisted account metadata.
Review details

Suppressed comments (2)

wire-ios-sync-engine/Source/SessionManager/SessionManager.swift:388

  • environment.isAuthenticated is true for a retained account whenever its non-expired auth cookie remains. The existing “Log out and keep data” path closes the session with deleteCookie: false, so this method still returns true after the session is torn down; the SSO callback then reports .alreadyLoggedIn and never reaches the identity-change alert/purge for the retained-account scenario. Base this check on loaded-session state (while retaining the active session during teardown) instead of the cookie.
        return environment.isAuthenticated(selectedAccount)
    }

wire-ios-sync-engine/Source/SessionManager/SessionManager.swift:1184

  • The new destructive purge path is not covered by the added tests: there is no test that verifies the account-data folder, cookies, user defaults, and account record are removed, nor that an active account is rejected or a deletion failure is handled. Please add focused SessionManager tests before relying on this flow to prevent partial cleanup or accidental data loss regressions.
        }
    }

    public func purgeRetainedAccountData(for userID: UUID) throws {
        guard let account = accountManager.account(with: userID) else { return }
  • Files reviewed: 20/20 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +386 to +388
public func isAccountActive(_ account: Account) -> Bool {
backgroundUserSessions[account.userIdentifier] != nil || environment.isAuthenticated(account)
}
Comment on lines 1208 to 1212
do {
try environment.cookieStorage(for: account).removeCookies()
} catch {
WireLogger.sessionManager.error("Failed to remove cookies: \(error)")
}
@github-actions

Copy link
Copy Markdown
Contributor

Test Results – batch 0

  2 files  173 suites   27s ⏱️
730 tests 730 ✅ 0 💤 0 ❌
731 runs  731 ✅ 0 💤 0 ❌

Results for commit 61ec1ea.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results – batch 2

1 141 tests   1 141 ✅  1m 22s ⏱️
  132 suites      0 💤
    1 files        0 ❌

Results for commit 61ec1ea.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results – batch 1

4 334 tests   4 307 ✅  6m 16s ⏱️
  551 suites     27 💤
    2 files        0 ❌

Results for commit 61ec1ea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants