Facebook login using Firebase results in Invalid OAuth access token error

2.5k views Asked by At

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.
2

There are 2 answers

0
Arkay On BEST ANSWER

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.

0
Caleb C. Adainoo On

Facebook Authentication App Type

If you're using React to do your authentication within the category specified, the option shown in the image worked for me.

You Can do same. This is from the updated version of Facebook's app type selection UI dated 5th January, 2022