flutter_web_auth icon indicating copy to clipboard operation
flutter_web_auth copied to clipboard

WebView Browser stays open after successful call to FlutterWebAuth.authenticate

Open mikeryder opened this issue 3 years ago • 3 comments
trafficstars

FlutterWebAuth 0.4.1

AndroidManifest.xml: <activity android:exported="true" android:name="com.linusu.flutter_web_auth.CallbackActivity" > <intent-filter android:label="flutter_web_auth"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="your-focus" /> </intent-filter> </activity>

Flutter call: final result = await FlutterWebAuth.authenticate(url: _authorizationEndpointUrl, callbackUrlScheme: 'your-focus'); String? code = Uri.parse(result).queryParameters['code']; print('MS365 Code: ' + (code ?? ""));

This prints the Code correctly, but the WebView Browser remains open.

The relevant section of the logcat:

2022-07-29 14:41:03.954 515-540/? I/ActivityTaskManager: Displayed org.chromium.webview_shell/.WebViewBrowserActivity: +193ms 2022-07-29 14:41:03.957 515-535/? D/EventSequenceValidator: Transition from ACTIVITY_LAUNCHED to ACTIVITY_FINISHED 2022-07-29 14:41:04.063 515-5660/? I/ActivityTaskManager: START u0 {act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=your-focus://auth/?code=xxxxxxx&session_state=040e2895-c9fa-44ba-ba65-c94575313b7e cmp=com.your_focus.app/com.linusu.flutter_web_auth.CallbackActivity (has extras)} from uid 10088 2022-07-29 14:41:04.063 515-535/? D/EventSequenceValidator: Transition from ACTIVITY_FINISHED to INTENT_STARTED 2022-07-29 14:41:04.071 515-535/? D/EventSequenceValidator: Transition from INTENT_STARTED to INTENT_FAILED 2022-07-29 14:41:04.072 515-5660/? W/ActivityTaskManager: Tried to set launchTime (0) < mLastActivityLaunchTime (3102689785)

I am connecting to the Microsoft OAUTH to get a token for Microsoft 365 Graph API.

Any thoughts on a fix or further debugging would be appreciated!

mikeryder avatar Jul 29 '22 18:07 mikeryder

@LinusU This is happening to me too. What's weird is that it worked the very first time I tried it, then subsequently failed all other attempts. I'm calling google OAuth and everything works fine, except that the webview stays open afterwards and redirects the user to www.google.com.

Edit : it seems according to https://bugs.chromium.org/p/chromium/issues/detail?id=545446 that it would suffice for the app to redirect to the main activity.

TheCarpetMerchant avatar Aug 06 '22 16:08 TheCarpetMerchant

Yo any solutions for this. the browser tab stays open after auth process.

s1dc0des avatar Mar 06 '23 20:03 s1dc0des

This is also happening for me.

Workaround: I found that if you set preferEphemeral to true, the browser closes after auth. But it also causes the browser to close if the user leaves it at all, so it doesn't help my situation as I want users to have the option to copy a MFA code from a different app - but when they return the browser will be closed.

Maybe preferEphemeral: true can help your case, but I would love the browser to close after auth whether it is true or false.

BBQRIBS72 avatar Mar 09 '23 10:03 BBQRIBS72