Skip to content

fix: Revoke API token when account creation fails - #2083

Merged
adrien-coye merged 2 commits into
masterfrom
ambrdctr-revoke-token-on-account-creation-failure
Nov 20, 2026
Merged

adrien-coye merged 2 commits into
masterfrom
ambrdctr-revoke-token-on-account-creation-failure

Conversation

@Ambrdctr

Copy link
Copy Markdown
Contributor

When login returns an API token but a later step of account creation fails (fetching the user profile, fetching drives, no usable drive, initializing the root, etc.), the new token was not always revoked and stayed valid server-side.

Same approach as Infomaniak/ios-kMail#2375 and Infomaniak/ios-euria#145:

  • Wrap the body of createAndSetCurrentAccount(token:) in do/catch. On any error, remove the token and account for token.userId, revoke the token, then rethrow.
  • Extract private func revokeApiToken(_:) from the existing remove-account path and reuse it.
  • Drop the ad-hoc cleanup in the "no drive" and "blocked/maintenance" branches since the catch now covers them.

Note for review: a failure late in the flow (e.g. initRoot()) now also logs the account out, whereas before it stayed logged in.

Copilot AI balanced review requested due to automatic review settings November 17, 2026 08:52

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

Failed web login for an already-connected user can revoke their existing session and delete cached drives and File Provider domains because rollback is not restricted to the session created by that attempt.

1 open issue
What changed in this PR

This PR centralizes failed-login cleanup in AccountManager to revoke newly issued API tokens when account setup fails.

Changes:

  • Wraps account creation in shared error handling that cleans up account state, requests token revocation, and rethrows the error.
  • Extracts a reusable token-revocation helper.
  • Removes branch-specific cleanup; late failures such as root initialization now also log the account out.
File Description
kDriveCore/​Data/​Cache/​AccountManager.swift Centralizes account-creation failure cleanup and shares token-revocation logic.

Review effort: Balanced

@Ambrdctr
Ambrdctr force-pushed the ambrdctr-revoke-token-on-account-creation-failure branch from 45dbfeb to 45bea5c Compare November 17, 2026 09:16
@adrien-coye
adrien-coye requested a balanced review from Copilot November 20, 2026 11:38

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.

🔵 Needs a closer look

Failed login cleanup can revoke an already-connected account’s valid token and delete its local data instead of limiting rollback to state owned by the failed attempt and separately revoking the newly issued token.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Ambrdctr and others added 2 commits November 20, 2026 13:38
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@adrien-coye
adrien-coye force-pushed the ambrdctr-revoke-token-on-account-creation-failure branch from 45bea5c to 32f711b Compare November 20, 2026 12:38
@sonarqubecloud

Copy link
Copy Markdown

@adrien-coye adrien-coye 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.

Discussed with @PhilippeWeidmann what was the goal of this PR.
Checked that inedded it does not impact the log-out policy on a server outage.
I check the log-out behaviour with some sample code.

@adrien-coye
adrien-coye merged commit e5f0052 into master Nov 20, 2026
13 of 14 checks passed
@adrien-coye adrien-coye added this to the 6.3.1 milestone Nov 20, 2026
@adrien-coye
adrien-coye deleted the ambrdctr-revoke-token-on-account-creation-failure branch November 20, 2026 13:19
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.

3 participants