Search code examples
facebookflutterfirebase-authenticationfacebook-loginflutter-facebook-login

Facebook login using Firebase results in Invalid OAuth access token error


My Flutter project is attempting to add a new user to Firebase Auth via Facebook login, which fails with the error:

I/flutter (30934): [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.","type":"OAuthException","code":190,"fbtrace_id":"MY_TRACE_ID"}} ]

I'm using the package

flutter_facebook_login: ^3.0.0
firebase_auth: ^0.18.3+1

and logging in via

FacebookLoginResult result = await FacebookLogin().logIn(['email']);
final auth.AuthCredential credential = auth.FacebookAuthProvider.credential(result.accessToken.token);
try {
  await auth.FirebaseAuth.instance.signInWithCredential(credential);
} catch (e){
  print(e);
}

The line in the try fails, and the error above is printed from the catch.

The Facebook login works fine, and I can see I've been correctly signed in to the app from my FB account. I have already tried the following solutions:

  1. Ensuring App ID and App Secret in the FB developer console, the firebase FB auth page, and within the app are all matching.
  2. In FB developer console gone to Settings -> Advanced and made "Is App Secret embedded in the client?" set to "No".
  3. Deleted FB App and remade.

Solution

  • Problem solved! Issue was with how the app is set up on the Facebook developer console. When first creating the app you are presented with the following menu

    enter image description here

    I originally selected "Build or Connect to a Game" as it says it is used when connecting to a gaming app played on or off the Facebook Platform, which is what best describes my app. I re-setup the app on FB, but now chose "Build Connected Experiences" and now it works. No idea why though.