feat: allow to resume the request if androdi OS kills the process - #1146
Open
Francesco-Voto wants to merge 1 commit into
Open
Francesco-Voto wants to merge 1 commit into
Francesco-Voto wants to merge 1 commit into
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ilteoood
reviewed
Sep 23, 2026
|
|
||
| private static final AtomicReference<Intent> sStashedAuthorizationResult = new AtomicReference<>(); | ||
|
|
||
| public static void stashAuthorizationResult(Intent data) { |
There was a problem hiding this comment.
Suggested change
| public static void stashAuthorizationResult(Intent data) { | |
| public static void stashAuthorizationResult(final Intent data) { |
|
|
||
| authService.performTokenRequest(tokenRequest, new AuthorizationService.TokenResponseCallback() { | ||
| @Override | ||
| public void onTokenRequestCompleted(TokenResponse resp, AuthorizationException ex) { |
There was a problem hiding this comment.
Suggested change
| public void onTokenRequestCompleted(TokenResponse resp, AuthorizationException ex) { | |
| public void onTokenRequestCompleted(final TokenResponse resp, final AuthorizationException ex) { |
Comment on lines
+282
to
+293
| } = {}) => { | ||
| if (Platform.OS !== 'android') { | ||
| return Promise.resolve(null); | ||
| } | ||
|
|
||
| validateHeaders(customHeaders); | ||
| validateConnectionTimeoutSeconds(connectionTimeoutSeconds); | ||
|
|
||
| return wrapNativeAuthPromise( | ||
| RNAppAuth.resumePendingAuthorize( | ||
| additionalParameters, | ||
| convertTimeoutForPlatform(Platform.OS, connectionTimeoutSeconds), |
There was a problem hiding this comment.
Suggested change
| } = {}) => { | |
| if (Platform.OS !== 'android') { | |
| return Promise.resolve(null); | |
| } | |
| validateHeaders(customHeaders); | |
| validateConnectionTimeoutSeconds(connectionTimeoutSeconds); | |
| return wrapNativeAuthPromise( | |
| RNAppAuth.resumePendingAuthorize( | |
| additionalParameters, | |
| convertTimeoutForPlatform(Platform.OS, connectionTimeoutSeconds), | |
| } = {}) => { | |
| const platform = Platform.OS | |
| if (platform !== 'android') { | |
| return Promise.resolve(null); | |
| } | |
| validateHeaders(customHeaders); | |
| validateConnectionTimeoutSeconds(connectionTimeoutSeconds); | |
| return wrapNativeAuthPromise( | |
| RNAppAuth.resumePendingAuthorize( | |
| additionalParameters, | |
| convertTimeoutForPlatform(platform, connectionTimeoutSeconds), |
This branch was successfully deployed
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.
Description
On Android, the OS can kill the app process while the user is away in the Custom Tab completing
login (e.g. under memory pressure). When the app restarts, React Native drops the resulting
activity result because it arrives before the JS context is ready
(react/react-native#30277), so the in-flight
authorize()promise is lost and the user'slogin silently fails to complete even though the browser already returned a valid response.
This adds a
resumePendingAuthorize()API to recover from that case:RNAppAuthModulenow stashes the raw activity result in a static field(
stashAuthorizationResult) when it's received with no in-flightauthorize()promise on themodule instance, instead of discarding it.
resumePendingAuthorizenative method and JS/TS export claim that stashed result,re-derive the token request from the
AuthorizationResponse(which carries the PKCE codeverifier), and complete the token exchange.
MainActivity.onActivityResulttoRNAppAuthModule.stashAuthorizationResultand callresumePendingAuthorize()on startup;it resolves
null(safe to call unconditionally) when there's nothing to resume, and alwaysresolves
nullon iOS.AuthorizationServiceconstruction andcreateCustomTabsIntentBuilder()off themain thread in
authorize(), since both are@WorkerThreadcalls that could block the UI forup to a second.
MainActivitywiring indocs/docs/usage/authorization.md.Steps to verify
MainActivity.onActivityResultto callRNAppAuthModule.stashAuthorizationResultas shown in the updated docs, and call
resumePendingAuthorize()on app startup.authorize()against a test IdP, and while the Custom Tab is open, kill the app processfrom Android Studio's Logcat ("Terminate Application") or via
adb shell am kill <package>.resumePendingAuthorize()should resolve with a valid token response instead of the flow silently failing.
authorize()flow still resolves as before, and thatresumePendingAuthorize()resolvesnullwhen called with nothing pending.resumePendingAuthorize()resolvesnullimmediately on iOS.