How to fix Platform Exception error "auth_in_progress" for flutter local authentication?
Asked Answered
S

7

12

I'm trying to implement fingerpritn authentication in my flutter app using local_auth plugin. But it is throwing me Platform Exception Error:

"PlatformException(auth_in_progress, Authentication in progress, null)"

final LocalAuthentication _localAuth = LocalAuthentication();
bool authenticated = false;
try {
  authenticated = await _localAuth.authenticateWithBiometrics(
    localizedReason: 'Scan your fingerprint to authenticate',
    useErrorDialogs: true,
    stickyAuth: false
  );
} on PlatformException
catch(e) {
  print(e);
}
return authenticated; }    
Slideaction answered 6/2, 2019 at 12:49 Comment(1)
I have the same problem.Veator
M
8

This happens on Android. You have to modify your MainActivity to implement FlutterFragmentActivity to use local_auth plugin. Change your code from this (Kotlin on my example):

import android.os.Bundle

import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    GeneratedPluginRegistrant.registerWith(this)
  }
}

To this:

import android.os.Bundle

import io.flutter.app.FlutterFragmentActivity
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterFragmentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    GeneratedPluginRegistrant.registerWith(this)
  }
}

Also you need to add this two lines to your gradle.properties file.

android.useAndroidX=true
android.enableJetifier=true

This error is hard to find since version 0.5.1, because the plugin doesn't throw the right exception, and the documentation doesn't tell you to implement this base class.

Met answered 14/6, 2019 at 22:23 Comment(3)
I am using local_auth: ^0.6.1+3. I am facing issue with GeneratedPluginRegistrant.registerWith(this) line. registerWith is expecting flutterEngine object and I am giving MainActivity context.Unnecessary
Doesn't work, unfortunately. Local auth works for the first time, but after you minimize an app and then mazimize, the auth activity appears but the app crashes when you touch a scannerCircumferential
@Circumferential any suggestion?Kellerman
K
2

I have found a simple solution. Before calling the LocalAuthentication().authenticate()

We can call await LocalAuthentication().stopAuthentication();

That helped me to fix the code

Ki answered 7/9, 2023 at 5:51 Comment(0)
B
1

I solved this issue:

  • Changing android/app/src/main/kotlin/MainActivity.kt
    package ....
   
    import androidx.annotation.NonNull;
    import io.flutter.embedding.android.FlutterFragmentActivity
    import io.flutter.embedding.engine.FlutterEngine
    import io.flutter.plugins.GeneratedPluginRegistrant
    
    class MainActivity: FlutterFragmentActivity() {
        override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
            GeneratedPluginRegistrant.registerWith(flutterEngine);
        }
    }
  • Is Disable, enable SplashScreenDrawable in AndroidManifest android/app/src/main/AndroidManifest.xml
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" />

or Java Version

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;


public class MainActivity extends FlutterFragmentActivity {

    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
    }
}
Bourdon answered 16/3, 2021 at 20:37 Comment(0)
H
0

I just solved this by removing android.useAndroidX=true and android.enableJetifier=true properties from my gradle.properties file.

This is all I have in my gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
Hash answered 10/10, 2020 at 11:6 Comment(0)
A
0

Solved by set the stickyAuth option as true in authenticate method.

auth.authenticate(
              stickyAuth: true,
              ...
          )

See the doc for more.

Aid answered 16/9, 2021 at 12:53 Comment(0)
X
0

I think its too late to response but as it said in local_auth docs :

you should use Sticky Auth and set it as true

it worked for me btw

 await _localAuthentication.authenticate(
          localizedReason: 'Please authenticate to show account balance',
          stickyAuth: true,
          biometricOnly: true);
Xenia answered 30/9, 2021 at 16:3 Comment(0)
W
0

I got same issue. But none of the above answers useful. Tricky solution is to set "sensitiveTransaction" value to false. By default this value is true.

When user clicks on biometric button, by default it will come two dialogs. One is faceid or fingerprint recognition and 2nd one is for confirmation dialog. At this case, if user clicks on cancel, permission denied and it will never asks again. If "sensitiveTransaction" sets to false will not ask for confirm after verified with faceid or fingerprint.

await localAuthObject.authenticate(
              localizedReason:
                  'Scan your fingerprint (or face or whatever) to authenticate',
              useErrorDialogs: false,
              sensitiveTransaction: false,
              stickyAuth: true,
              biometricOnly:
                  false);
Weanling answered 10/2, 2022 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.