flutter_web_auth
flutter_web_auth copied to clipboard
authenticate method never complete if cancelled on Android
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
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
@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?
PRs welcome!
I got it - but I couldn't have done it with some help by @passsy 🎉 Fixed in this PR: #28
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
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.
@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? ;-)
I'll try
@izht the flutter bloc is still working, but it waits until the previous event ended. As you use a
await
it waits until theFlutterWebAuth
call is done. But this never happens when you pressclose
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 :)
This was fixed in #28, released as 🚢 0.2.3 / 2020-05-11