skip to Main Content

Package version used:

flutter_facebook_auth: ^7.0.0
firebase_core: ^2.24.2
firebase_auth: ^4.15.2
FBSDKLoginKit (17.0.2) //pod

I have tested recently with our app and can’t login with Facebook and upon debugging, I’ve seen this error

Unhandled Exception: [firebase_auth/invalid-credential] {"code":190,"message":"Bad signature"}

Login attempt code:

Future<dynamic> signInWithFacebook() async {
  // try {
    final LoginResult loginResult = await _facebookAuth.login();

    if (loginResult.accessToken == null) {
      _hasError = true;
      _loginErrorMsg = 'Login cancelled.';
      notifyListeners();
      return null;
    }

    // Create a credential from the access token
    final OAuthCredential facebookAuthCredential =
        FacebookAuthProvider.credential(loginResult.accessToken!.tokenString);

    UserCredential userCredential = await FirebaseAuth.instance
        .signInWithCredential(facebookAuthCredential);
}

The result of loginResult is LoginStatus.success.

Is someone experiencing the same issue? What are the steps have you done to resolve?

2

Answers


  1. The credentials used to authenticate the Admin SDKs cannot be used to perform the desired action. Certain Authentication methods such as createCustomToken() and verifyIdToken() require the SDK to be initialized with a certificate credential as opposed to a refresh token or Application Default credential. See Initialize the SDK for documentation on how to authenticate the Admin SDKs with a certificate credential.

    For iOS

    <key>FacebookAppID</key>
        <string>xxxxxxxxx</string>
        <key>FacebookClientToken</key>
        <string>xxxxxxxxx</string>
        <key>FacebookDisplayName</key>
        <string>xxxxxxxxx</string>
        <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>fbapi</string>
            <string>fb-messenger-share-api</string>
            <string>fbauth2</string>
            <string>fbshareextension</string>
             <string>sms</string>
             <string>tel</string>
        </array>
        <key>LSRequiresIPhoneOS</key>
        <true/>
        <key>FacebookAutoLogAppEventsEnabled</key>
     <true/>
    
    Login or Signup to reply.
  2. I have the same issue, below code that issue

    Future<UserCredential?> signInWithFacebook(BuildContext context) async {
      final rawNonce = generateNonce();
      final nonce = sha256ofString(rawNonce);
      // Trigger the sign-in flow
      final LoginResult loginResult = await FacebookAuth.instance
          .login(
        loginTracking: LoginTracking.limited,
        nonce: nonce,
      )
          .catchError((onError) {
        if (kDebugMode) {
          //print(onError);
        }
        throw Exception(onError.message);
      });
    
      if (loginResult.accessToken == null) {
        throw Exception(loginResult.message);
      }
      // Create a credential from the access token
      OAuthCredential facebookAuthCredential;
    
      print("tokenType${loginResult.accessToken!.type}");
    
      if (Platform.isIOS) {
        switch (loginResult.accessToken!.type) {
          case AccessTokenType.classic:
            final token = loginResult.accessToken as ClassicToken;
            facebookAuthCredential = FacebookAuthProvider.credential(
              token.authenticationToken!,
            );
            break;
          case AccessTokenType.limited:
            final token = loginResult.accessToken as LimitedToken;
            facebookAuthCredential = OAuthCredential(
              providerId: 'facebook.com',
              signInMethod: 'oauth',
              idToken: token.tokenString,
              rawNonce: rawNonce,
            );
            break;
        }
      } else {
        facebookAuthCredential = FacebookAuthProvider.credential(
          loginResult.accessToken!.tokenString,
        );
      }
    
      // Once signed in, return the UserCredential
      return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
    }
    

    Generates a cryptographically secure random nonce, to be included in a
    credential request.

      String generateNonce([int length = 32]) {
        const charset =
            '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
        final random = Random.secure();
        return List.generate(length, (_) => charset[random.nextInt(charset.length)])
            .join();
      }
    
      /// Returns the sha256 hash of [input] in hex notation.
      String sha256ofString(String input) {
        final bytes = utf8.encode(input);
        final digest = sha256.convert(bytes);
        return digest.toString();
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search