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
51 stars 50 forks source link

[Bug]: Android future never return when close web view #87

Open dagovalsusa opened 9 months ago

dagovalsusa commented 9 months ago

Description

Hi,

on Android the authenticate future never return when close web view, I have tried also catching error, but nothing e never return.

Minimal Reproduction

Steps to reproduce the behaviour:

  1. Use the following code:
    try {
      log("HERE bis $result");
      result = await FlutterWebAuth2.authenticate(
          url: url.toString(), callbackUrlScheme: 'myscheme', options: FlutterWebAuth2Options(timeout: 100, preferEphemeral: true, intentFlags: ephemeralIntentFlags));
      log("HERE tris $result");
    } catch (e, s) {
      log("HERE catch $result");
      FirebaseCrashlytics.instance.recordError(e, s);
      PlatformException exc = (e as PlatformException);
      if (exc.code == "CANCELED") return;
    }

Exception or Error

no error logs

Expected Behaviour

I will expected a null value, or a exception

Screenshots

No response

Additional context

No response

Device

Android Emulator Pixel 4

OS

Android

Browser

Chrome

Flutter version

3.16

flutter_web_auth_2 version

3.0.4

Checklist

ThexXTURBOXx commented 9 months ago

As described in the documentation, timeout does not work on Android. Did you follow all the setup steps as described here?

dagovalsusa commented 9 months ago

Yes, I have setup all steps, also on AndroidManifest.

<application
        android:label="------"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:usesCleartextTraffic="false"
        android:debuggable="false"
        android:allowBackup="false">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" />
                <data android:host="my host" />
            </intent-filter>
        </activity>

        <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="myscheme" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.yalantis.ucrop.UCropActivity"
            android:screenOrientation="portrait"
            android:exported="false"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
tinu2610 commented 9 months ago

webview disappear when I press recent app or home button in android device. final result = await FlutterWebAuth2.authenticate( url: url, callbackUrlScheme: Constants.callbackUrlScheme, options: const FlutterWebAuth2Options(intentFlags: ephemeralIntentFlags), );

ThexXTURBOXx commented 9 months ago

@tinu2610 You are using ephemeralIntentFlags. This is exactly the intended behaviour when using those.

tinu2610 commented 9 months ago

@ThexXTURBOXx then how can I avoid that situation. I don't want multiple instances of webview. if i'm using ephemeralIntentFlags then after switching my original app with another app the WebView will completely disappear.

As linkedln using within app webview can we use same as from this package.

ThexXTURBOXx commented 9 months ago

This is a question you should be asking on Stack Overflow. Please don't hijack issues on GitHub for questions like these. This makes it hard for maintainers to keep track of real issues within their packages.