-
Notifications
You must be signed in to change notification settings - Fork 143
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
Android 12: Authentication fails when screen orientation changes (AuthenticationException) #530
Comments
That was a very detailed and nice bug report I would say. I was curious and tinkering with it and figured that onResume will always be called after onNewIntent but there is no guarantee on when it will be called.
On API Level 30 you can see that onResume is called after onNewIntent when new instance of activity is created due to configuration change Call Stack in API Level 30
On API Level 31 onResume is called before onNewIntent, but since there is a finish call inside the onResume call we never wait to receive the onResume after the onNewIntent. Call Stack in API Level 31
When I add a small delay to the finish inside onResume, onNewIntent seems to finish its promise of calling onResume Call Stack in API Level 31 after introducing a delay
Introducing a delay to wait for lifecycle callback feels like a hack though. |
Those were my observations a well 💯 I agree that the delay seems like a hack and I think I've seen some suggestions on StackOverflow about using a |
I was able to fix this issue by locking the orientation of RedirectActivity and AuthenticationActivity. This won't affect the existing flow/features since the "Web View" we show inside the app can still handle orientation change. This is the sanest solution in my opinion since this will avoid us handling the complicated life cycle of Screen Orientation in Single Task activity without losing any ability. The animation is one thing to check for and it isn't affected much. So I would actually like to proceed with this. |
Thanks for providing all the details here! And hi @poovamraj 👋 ! It looks like in Lock.Android we fix the activity to portrait mode, so perhaps we can consider that here as well as quick fix. Is that what you did to fix the issue? Either way, in talking with the team, it would probably be good to spend some time investigating why this changed in API 31 and if the issue is related to the activity instance (context) passed to the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇♂️ |
Describe the problem
The authentication via browser seems to have an issue on Android 12 only if the process ends with a screen orientation different than the client's app's
Activity
that is hosting it.For example, when my
LoginActivity
is in portrait when I callWebAuthProvider.login()
, and I finish the authentication process in the browser in landscape, then I am getting anAuthenticationException
back withisCanceled == true
in myLoginActivity
I've also tested this scenario with Android 11, Android 10, and Android 8.0 and it is not happening. So my guess is that it has to do with something Android 12 specific.
What was the expected behavior?
Expected behavior would be to get a
onSuccess
callback from theWebAuthProvider
no matter the screen's orientationReproduction
Steps to reproduce
In my
LoginActivity
, I'm doing a simple login call that you can trigger just from clicking on a button:For the callback, you can just add logs in them to see what is going on:
To make it even easier to test, in the app manifest, add
android:screenOrientation="portrait"
within your host activity.Now:
HostActivity: The user closed the browser app and the authentication was canceled
screenOrientation="portrait"
in the manifest and I am getting the same result if I start with the host activity in landscape, and login in the browser in portrait.My findings while debugging
Below are what I have been seeing while trying to debug:
The difference between staying on the same screen's orientation and changing, is that the
onNewIntent
inAuthenticationActivity
does not get called on Android 12 if the orientation changes. Which I think is the issue because theintent
with the authentication data is lost (or not set), which ends up with an intent in theonResume()
of theAuthenticationActivity
having its datanull
, which triggers theRESULT_CANCELED
.onNewIntent
does get called.I am also having another error on Android 12 when coming back to the host app (which you might see as well):
onResume
being called while the screen animation is happening, which maybe is the case when the phone is rotating the host activity's screen.Just for the record, the full error stackTrace I get from the auth0 library when the error happens is the following:
but like I said, it's triggered because the
intent.getData()
isnull
.In my case, an easy fix would have been to have the ability to lock the Authentication process to a particular orientation, which I haven't found so far, but I can see that this would not fix the issue for other people experiencing the same problem with both orientation available.
Environment
I hope you can reproduce it as easily as I can, and I apologize in advance if my english is not 100% right as it is not my first language 😄
The text was updated successfully, but these errors were encountered: