fix(android-sdk): discard in-flight token responses after sign-out#264
Merged
Conversation
) * fix(android-sdk): discard in-flight token responses after sign-out * fix(android-sdk): run in-flight token flows on credential snapshots * fix(android-sdk): complete stale token flows with NOT_AUTHENTICATED consistently * refactor(android-sdk): rename SessionGuard to CredentialGuard (cherry picked from commit 6a84601)
There was a problem hiding this comment.
Pull request overview
Backport to the v2 Android SDK to prevent in-flight token refresh / authorization-code exchanges from persisting tokens after signOut(), which could otherwise resurrect cleared credentials.
Changes:
- Add an in-memory optimistic “generation” guard (
CredentialGuard) to invalidate/commit credential writes and discard stale token flows after sign-out. - Update
signIn()andgetAccessToken()refresh flow to snapshot credentials and commit token responses only if still current. - Add deterministic unit tests covering refresh/sign-in races around
signOut()(including JWKS/OIDC-config in-flight cases).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| android-sdk/android/src/main/kotlin/io/logto/sdk/android/LogtoClient.kt | Introduces CredentialGuard, atomic credential dropping, and guarded persistence of token responses to prevent post-sign-out credential resurrection. |
| android-sdk/android/src/test/kotlin/io/logto/sdk/android/LogtoClientTest.kt | Adds race-condition unit tests and supporting helpers to validate stale refresh/sign-in results are discarded after sign-out. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wangsijie
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backports #263 to the
v2.xmaintenance line (cherry-pick -xof6a84601, fixes #253 for v2): an in-flight token refresh (or sign-in code exchange) landing aftersignOut()no longer resurrects the cleared credentials. See #263 for the full design discussion (CredentialGuardoptimistic lock, credential snapshots for in-flight reads, stale flows complete withNOT_AUTHENTICATED).Conflict resolution beyond the clean hunks, due to the v2/v3 divergence (v3 replaced WebView with Custom Tabs and split sign-out into
clearCredentials+ browsersignOutin #249/#251):signOut(completion)keeps its WebView cookie clearing and now drops credentials through the same atomicdropCredentials(); v3's browser-basedsignOut(context, ...)overload andclearCredentialsdo not exist on v2 and were not introduced.signOut(), mockedCookieManager, and the sign-in race driven through the WebView-eraLogtoAuthManager/LogtoWebViewAuthActivityflow instead of the Custom Tabs one.No public API changes;
NOT_AUTHENTICATEDis reused (no new exception type), so the patch stays source- and binary-compatible for v2 consumers.Testing
unit tests — the seven race tests from #263 ported to the v2 flow; red-check verified against the unfixed v2 implementation (exactly those 7 fail, the existing 26 pass; all 33 pass with the fix).
Checklist
.changeset(N/A — this repo uses release-please)🤖 Generated with Claude Code