Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library does not correctly handle app process termination (activity re-creation) within authorize roundtrip #773

Open
dolly22 opened this issue Sep 16, 2022 · 2 comments
Labels
issue-accepted This issue has been confirmed and accepted by the maintainers

Comments

@dolly22
Copy link

dolly22 commented Sep 16, 2022

Issue

Related to issues #600, #672 and PR #743

TL;DR Library holds some references in instance variables in RNAppAuthModule. When app process restarts (is stopped in background) when custom browser tab is displayed those instance variables are lost when new process is created. It always results in failed authorization, but sometimes application also crashes when accessing those uninitialized instance variables.

How to reproduce

  1. Start authentication within your application
  2. When custom browser tab is displayed kill application with adb shell am kill com.app (browser tab stays visible)
  3. Finish authentication within browser tab

After authentication roundtrip if finished application process cold starts. There might be two outcomes depending if authorization Activity is correctly resumed or not. But both effectively result in failed authorization.

Details

If mentioned react native bug is worked around with some method like this and all Activity results are delivered to application the outcome changes and application crash is now deterministic on null reference exceptions.

There is also more discussion about this react native bug, and also some other library approaches - react-native-image-picker/react-native-image-picker#1502

Possible fix discussion

To my understanding this will not be possible to correctly support authorization continuation after cold start without somewhat changing library api surface. There are multiple issues here.

Deliver activities from last session to javascript

We need another way how to deliver resumed startup activity results (RNAppAuthModule/onActivityResult) to javascript code as original authorize() Promise is already long lost and javascript was started from scratch after new application process was created.

I currently do use something like this in my workaround to deliver authorize results to application if no authorize() promise is available...

export function subscribeAuthorizeResultCallback(callback: (error?: Error, data?: AuthorizeResult) => void): Promise<void>

Flow contextual information to onActivityResult

There is no easy way how to flow contextual information from RNAppAuthModule/authorize to RNAppAuthModule/onActivityResult in case of process restart. It seems AppAuth-android library currently does not support flowing any custom information through result Intent.

Some values might be read from AuthorizationResponse.request that is available, but there are still some others like clientSecret, dangerouslyAllowInsecureHttpRequests that we need there.

@AntonL-tech
Copy link

Any updates on this one?

@carbonrobot carbonrobot added needs-triage Waiting for a member of the team to confirm issue-accepted This issue has been confirmed and accepted by the maintainers and removed needs-triage Waiting for a member of the team to confirm labels May 2, 2024
@carbonrobot carbonrobot pinned this issue May 2, 2024
@carbonrobot
Copy link
Contributor

carbonrobot commented May 2, 2024

While we monitor the upstream issue in React Native core, which has been open for several years, we are exploring secure alternatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue-accepted This issue has been confirmed and accepted by the maintainers
Projects
None yet
Development

No branches or pull requests

3 participants