bitfireAT / davx5-ose

DAVx⁵ is an open-source CalDAV/CardDAV suite and sync app for Android. You can also access your online files (WebDAV) with it.
https://www.davx5.com
GNU General Public License v3.0
1.27k stars 69 forks source link

[Nextcloud login flow] Check for successful authentication whenever a new custom tab page has loaded #548

Closed rfc2822 closed 3 months ago

rfc2822 commented 4 months ago

Currently, users are required to press the close button of the custom tabs after successful authentication. It would improve UX if this wasn't necessary.

I think it should be possible to [get notified from the custom tabs when a new page has been loaded over CustomTabsCallback.NAVIGATION_FINISHED](https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsCallback#NAVIGATION_FINISHED()).

Whenever a new page has loaded, we could call model.checkCallback(ignoreErrors = true).

ArnyminerZ commented 4 months ago

I think I've done it at some point in the past, so it's definitely possible.

rfc2822 commented 3 months ago

@ArnyminerZ Are you interested in giving it a try?

ArnyminerZ commented 3 months ago

I can take a look, for sure. I'll get to work into it after finishing #575 which is what I'm currently working on. Almost finished.

ArnyminerZ commented 3 months ago

Well, after a lot of tinkering, searching and trying things out, it's not clear if this can be done. The issue is that custom tabs cannot be closed, there's no way to do so.

I'm able to detect when the login process is complete, but there's no way of hiding the tabs. There's some people that suggest that if you launch the activity again after storing its state somehow, the tabs hide, but I've not been able to reproduce.

I've found this gist, but it's quite outdated, and I've not been able to understand well enough how it works.

I've tried manually launching the activity from the fragment once the login process is complete, but the custom tabs pause the activity, so an IllegalStateException is thrown:

java.lang.IllegalStateException: Fragment NextcloudLoginFlowFragment{b808422} (8492594e-dc81-4227-8bba-f71fd7bbde68) not attached to Activity

Maybe through some broadcast like with the gist above it's possible, but I think it's too much for so little benefit, it's just closing the window.

The other way possible is adding an intent filter for a custom schema (app:// for example, or davx5), but it's the website who has to make the redirection, and I've not found any way to set a custom redirect url for Nextcloud (at least not in the docs or elsewhere)

ArnyminerZ commented 3 months ago

I've opened #584 just in case you want to check it out, maybe you know another way of launching the activity.

Whatever the case, I don't trust launching the activity again works, because if don't close the custom tab, and launch the app again in Android Studio, the tab is not closed, so I don't think even this would work.

rfc2822 commented 3 months ago

The other way possible is adding an intent filter for a custom schema (app:// for example, or davx5), but it's the website who has to make the redirection, and I've not found any way to set a custom redirect url for Nextcloud (at least not in the docs or elsewhere)

We can't use custom URI schemes with Nextcloud, which is the reason why we have to use Login Flow 2 (v1 uses nc:// redirect).

Well, after a lot of tinkering, searching and trying things out, it's not clear if this can be done. The issue is that custom tabs cannot be closed, there's no way to do so.

Bad, but really looks like that. So I'll close this issue + PR for now. Maybe there's a way someday.