auth0 / Auth0.Android

Android toolkit for Auth0 API
https://auth0.com
MIT License
221 stars 138 forks source link

Universal Login not working on instant apps #536

Closed fpitters closed 2 years ago

fpitters commented 2 years ago

Describe the problem

On an instant app enabled application with Auth0 Universal Login, the login website (Custom Tab) is not getting opened.

Not entirely sure this is a bug but a limitation of instant apps to use explicit intents with package name included. When using CustomTabsIntent.Builder(CustomTabsSession) constructor, the package name is set on the intent, and I think that makes the startActivity to fail.

Do you know if would there be anyway to overcome above limitation?

What was the expected behavior?

Web Universal Login to work on instant apps.

Reproduction

Enable instant app configuration on sample application: https://github.com/fpitters/Auth0.Android/commit/7c5f6a401e372ac6b9a08fdb309b00a1f61b6198

Run the app as an instant app How to

Try to launch "LOG IN WITH BROWSER"

Nothing happens and the log shows:

E/CustomTabsController: Could not find any Browser application installed in this device to handle the intent.

Environment

Reproducible on any device Reproducible on a One Plus 8T with Android 11

poovamraj commented 2 years ago

@fpitters I tried with the fork you provided and it seems to work correctly. Could the issue really be that there is no browser installed on the device? Both Chrome Custom Tabs and the External Browser method worked.

Please feel free to reopen this issue if the issue persists.

fpitters commented 2 years ago

Thanks @poovamraj for checking this.

I'm able to reproduce on a One Plus 8T with Google Chrome installed, among others.

Could you double check you have installed the app as Instant app? Make sure the app is deleted first, and toggle the Android Studio setting for it on Run configurations.

poovamraj commented 2 years ago

Hi @fpitters, I did ensure that the app was installed as an Instant app. I remember testing this in API Level 30. Can you share which Android version you used?

Also, can you share the exception thrown in this line along with its stack trace - https://github.com/auth0/Auth0.Android/blob/main/auth0/src/main/java/com/auth0/android/provider/CustomTabsController.java#L121?

fpitters commented 2 years ago

It's API 30 too.

The exception is:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://lbalmaceda.auth0.com/... pkg=com.android.chrome (has extras) }

I think setting the package name on the intent is not allowed as mentioned in https://developer.android.com/topic/google-play-instant/getting-started/instant-enabled-app-bundle#access-installed-apps

poovamraj commented 2 years ago

To give you an update on this issue. I was initially testing this in an emulator and everything seems to work fine there.

The same issue was reproducing when I ran it on a real device.

I was able to avoid this issue when I commented out the part where we wait for 1 second for CustomTabs service to bind. or when I ran this code outside of the new thread in the launchUri. I am still analyzing the implications and why this is happening. We will keep on working on this and try to provide a fix. Will keep you updated along the way as well. Thanks for reporting this issue.

poovamraj commented 2 years ago

Hi @fpitters, I checked the issue and looks like it reproduces only in One Plus phones and not in other real devices (That is why it didn't reproduce for me in the Emulator). The vendor runs a custom version of Android and their repository doesn't seem to be up to date for me to understand the issue on their end. Though this is a niche topic where the instant app is not working only for Oneplus phones, I want to try and think of a generic solution that won't affect other devices as well (Though the hope of it feels less).

Again, will keep you posted about this. Thanks for providing information on the device you tested without which I wouldn't have been able to solve it.

fpitters commented 2 years ago

Hi @poovamraj, you are absolutely right, I can't reproduce on other devices, I though I was able to reproduce it on at least some other. But some Xiaomis and Samsungs I have here are working fine. Sorry for the confusion.

Yes please keep us updated, and let us know if you need help testing anything.

poovamraj commented 2 years ago

@fpitters, considering this is a vendor-specific issue happening only for Instant Apps, we have noted down this in our backlog but couldn't provide a proper timeline on when the fix will be available. Since we are tracking this in our backlog, I will be closing this issue for now. Please feel free to comment here or reopen this ticket if you have more details on this. Thanks for understanding