ThexXTURBOXx / flutter_web_auth_2

Flutter plugin for authenticating a user with a web service
https://pub.dev/packages/flutter_web_auth_2
MIT License
57 stars 55 forks source link

[Bug]: Minimizing an external browser window causes a FlutterWebAuth2.authenicate exception. #132

Open mgeilich opened 1 month ago

mgeilich commented 1 month ago

Description

Can minimizing a browser window not cause a FlutterWebAuth2.authenticate exception? If not, is there a way to close an external browser window on an exception?

In a locked-down network on Android, I must use Microsoft Edge, not Chrome so I have implemented FlutterWebAuth2 using an Android intent-filter instead of a webView to launch the Edge browser. If I minimize the browser window instead of filling in credentials, the authenicate() call fails with an exception. This in itself is OK, but it leaves the browser window minimized, which can then be maximized and filled-in, even though the code is no longer waiting for it.

Minimal Reproduction

Minimize the browser window launched by FlutterWebAuth2.authenticate:

 <activity
        android:name="com.linusu.flutter_web_auth_2.CallbackActivity"
        android:exported="true">
        <intent-filter android:label="flutter_web_auth_2">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="XXXXXXXX" />
        </intent-filter>
  </activity>
  late final String responseString;
  try {
    responseString = await FlutterWebAuth2.authenticate(
      url: authorizationUrl.toString(),
      options: FlutterWebAuth2Options(intentFlags: ephemeralIntentFlags),
      callbackUrlScheme: kIsWeb ? 'https' : "custom",
    );
  } catch (e) {
    printError("oauth 2.0", "FlutterWebAuth2.authenticate failure: $e");
  }

Exception or Error

PlatformException(CANCELED, User canceled login, null, null)

Expected Behaviour

Best would be if minimizing the browser window did not cause a platform exception, but instead allowed the authenticate() call to wait.

Screenshots

No response

Additional context

No response

Device

SM T220

OS

Android

Browser

Edge

Flutter version

3.24.1

flutter_web_auth_2 version

3.0.0

Checklist