Home > Enterprise >  "Lost connection to device" on specific hardware during web authentication
"Lost connection to device" on specific hardware during web authentication

Time:06-29

I have an application that implement web authentication using flutter_web_auth 0.4.1 package.

When i test my implementation on a samsung smartphone, everything work like a charm. The Chrome browser launch on authentication website, after authentication i came back in my application and view is refreshed like i need.

But when i test my implementation on a Huawei tablet, just after chrome launch, i lost connection. After authenticating i came back in my application, but i can see that application is reloading (I can see splash screen) without saving token as i always came back to login screen.

Here is my implementation:

Function that authenticate (called by an ElevatedButton onPressed event) :

  authenticate() async {
    final result = await FlutterWebAuth.authenticate(
        url: "https://xxxx.yyyy.eu/auth/login?authorize=yes",
        callbackUrlScheme: "com.example.zzzzzzzz");
    final token = Uri.parse(result).queryParameters['token'] ?? '';

    // Save token
    var prefs = await SharedPreferences.getInstance();

    prefs.setString("token", token);

    refreshAfterAuthentication();
  }

AndroidManifest.xml :

<activity 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="com.example.zzzzzzzz" />
    </intent-filter>
</activity> 

Web redirection after authentication (Angular app) :

window.location.href = 'com.example.zzzzzzzz://success?token='   data.token;

As i lost connection, just after chrome launch, i can't see log in console about what is causing the application reload after redirecting to it.

Is there another way to debug this case ?

Edit :

Smartphone run under Android 9 and tablet under android 8. Is it possible that web auth can't be implemented on Android 8 ?

CodePudding user response:

do you have internet permission in android manifist.xml?

    <uses-permission android:name="android.permission.INTERNET"/> 

if the answer is yes I think you have to add timeOut to your request :

final result = await FlutterWebAuth.authenticate(
        url: "https://xxxx.yyyy.eu/auth/login?authorize=yes",
        callbackUrlScheme: "com.example.zzzzzzzz").timeout(
      Duration(seconds: 5000),
    );

CodePudding user response:

I solved this issue by adding an exported attibute to activity in AndroidManifest.xml, like this :

AndroidManifest.xml:

    <activity android:name="com.linusu.flutter_web_auth.CallbackActivity" android:exported="true"> 
        <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="com.example.andidoor" />
        </intent-filter>
    </activity> 

Android reference: https://developer.android.com/guide/topics/manifest/activity-element#exported

  • Related