flutter_web_auth icon indicating copy to clipboard operation
flutter_web_auth copied to clipboard

authenticate method never complete if cancelled on Android

Open izht opened this issue 5 years ago • 9 comments

Hi,

I found some problem when closing the tab before authentication completed. My expect behaviour is it will throw an error from FlutterWebAuth.authenticate but on Android it didn't

My code is

final result = await FlutterWebAuth.authenticate(
      url: 'http://something?redirect_uri=myapp://authen',
      callbackUrlScheme: 'myapp',
    );
final code = Uri.parse(result).queryParameters['code'];

I debugged final code line but it will never reach there, also it don't throw any error

On iOS, it doesn't have same issue. When I'm closing the web tab I would get a PlatformException(EUNKNOWN, The operation couldn’t be completed. (com.apple.AuthenticationServices.WebAuthenticationSession error 1.), null)} } and can just use try-catch to handle it

And somehow it create an issue with my flutter_bloc's bloc, after tab was closed flutter_bloc's stream stop taking any event. I've got no idea how it can relate but here I would want to capture that cancelling tab because if I do I think I won't have that problem because on iOS it works perfectly

izht avatar Feb 10 '20 02:02 izht

I am using ebay oauch which has https:/ based redirect_url This plugin does not capture it https://developer.android.com/training/app-links/verify-site-associations.html

ghost avatar Mar 02 '20 09:03 ghost

@izht the flutter bloc is still working, but it waits until the previous event ended. As you use a await it waits until the FlutterWebAuth call is done. But this never happens when you press close on the custom tab. I hope this helps you to understand the flutter bloc side better?

I have seen that you forked it and fixed the issue, have you published your version somewhere or can create a pull request?

Knupper avatar Apr 01 '20 05:04 Knupper

PRs welcome!

LinusU avatar Apr 13 '20 11:04 LinusU

I got it - but I couldn't have done it with some help by @passsy 🎉 Fixed in this PR: #28

mreichelt avatar Apr 21 '20 16:04 mreichelt

And here's a video that it works (and I verified it continues to work on iOS, as expected): https://www.youtube.com/watch?v=5_UtRV8w2ak

mreichelt avatar Apr 21 '20 16:04 mreichelt

My redirect uri is "https://mydomain.com/redirect?askdjajdkajk" I was able to fork and dirty patch for myself. But is it possible that @mreichelt can test this plugin for "https" based redirect uri. I am happy to help test.

ghost avatar Apr 22 '20 11:04 ghost

@sanni-aubergine I didn't check with https - but if you could reproduce and even patch the problem yourself locally, why not create a PR yourself? ;-)

mreichelt avatar Apr 22 '20 14:04 mreichelt

I'll try

ghost avatar Apr 23 '20 18:04 ghost

@izht the flutter bloc is still working, but it waits until the previous event ended. As you use a await it waits until the FlutterWebAuth call is done. But this never happens when you press close on the custom tab. I hope this helps you to understand the flutter bloc side better?

I have seen that you forked it and fixed the issue, have you published your version somewhere or can create a pull request?

Hey, sorry didn't check msg for awhile.

With my change (https://github.com/izht/flutter_web_auth/commit/154bcf438511cd91e0686b25f6b57c06dc94d62b), I ended up need to add following code to MainActivity.kt to my project as well not just example

override fun onResume() {
        if(FlutterWebAuthPlugin.tabOpened){
            FlutterWebAuthPlugin.callbacks.remove(FlutterWebAuthPlugin.urlScheme)?.success("fail")
            FlutterWebAuthPlugin.tabOpened = false
        }
        super.onResume()
    }

quite a hacky way imo and not a friendly lib to use

looking forward PR https://github.com/LinusU/flutter_web_auth/pull/28 tho :)

izht avatar Apr 29 '20 17:04 izht

This was fixed in #28, released as 🚢 0.2.3 / 2020-05-11

LinusU avatar Nov 01 '22 09:11 LinusU