The supplied auth credential is malformed or has expired. - Flutter Facebook Login

2,916

I think your key hashes in facebook app is malformed. Facebook app needs Base64 key hashes to work. You have to encode your SHA1 fingerprint from android keystore to Base64.

To do that simply run this line of javascript code in browser console

btoa('your SHA1 key here'.split(':').map(hc => String.fromCharCode(parseInt(hc, 16))).join(''))

Paste the output you receive to key hashes in setting > basic panel of your facebook app on Facebook for Developers

Share:
2,916
mcfred
Author by

mcfred

A curious mindset and a solid hunger to learn more each day.

Updated on December 26, 2022

Comments

  • mcfred
    mcfred over 1 year

    I am trying to implement FacebookLogin in my flutter app using Firebase Realtime Database. I am able to login to my app. However, when I try to fetch something from the Database using the FB's auth token, I get the following error:

     E/flutter (30549): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [firebase_auth/invalid-credential] The supplied auth credential is malformed or has expired. [ Unsuccessful debug_token response from Facebook: {"error":{"message":"Invalid OAuth access token signature.","type":"OAuthException","code":190,"fbtrace_id":"AwuVQUt6tCG1go"}} ]
    

    Here's my facebook login code:

    Future signInFB() async {
          var facebookLogin = FacebookLogin();
        var facebookLoginResult =
            await facebookLogin.logIn(['email']);
         switch (facebookLoginResult.status) {
          case FacebookLoginStatus.error:
            break;
          case FacebookLoginStatus.cancelledByUser:
            print("CancelledByUser");           
            break;
          case FacebookLoginStatus.loggedIn:
            print("LoggedIn");
            var graphResponse = await http.get(
                'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email,picture.height(200)&access_token=${facebookLoginResult
                    .accessToken.token}');
              fbToken = facebookLoginResult.accessToken.token.toString();
        var profile = json.decode(graphResponse.body);
        final FirebaseAuth _auth = FirebaseAuth.instance;
        print('Token is ' + fbToken); 
        final OAuthCredential credential =  FacebookAuthProvider.credential(fbToken); 
        final User user = (await _auth.signInWithCredential(credential)).user;
        assert(!user.isAnonymous);
        assert(await user.getIdToken() != null);
         _token = await user.getIdToken();
         _userId = user.uid;
        print('Profile is ' + profile.toString());
        break;
      }
      }