Login through Facebook using OAuth issue with Firebase (App_id in the input_token did not match the Viewing App)

Viewed 6068

I am trying to login through Facebook, collect some data over OAuth and then login to Firebase using the credential. I am however encountering an issue (please see logs below).

CODE EXAMPLE

@objc func signInWFB() {

    let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()

    fbLoginManager.logIn(withReadPermissions: ["email","user_birthday","user_gender"], from: self) { (result, error) -> Void in

        if (error == nil) {
            let fbloginresult : FBSDKLoginManagerLoginResult = result!
            if (result?.isCancelled)! {
                print(result ?? FBSDKLoginManagerLoginResult())
            } else if(fbloginresult.grantedPermissions.contains("email")) {
                if((FBSDKAccessToken.current()) != nil) {
                    FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email, birthday, gender"]).start( completionHandler: { (connection, result, error) -> Void in
                        if (error == nil) {
                            //everything works print the user data
                            print(result ?? AnyObject.self)

                            if let d = result as? [String:Any] {

                                // ALL GOOD UP TO HERE

                                let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current()!.tokenString)

                                Auth.auth().signIn(with: credential) { (authResult, error) in
                                    if let error = error {
                                        print(error) // ERROR HERE
                                        return
                                    }

                                    // ...
                                }
                            }
                        }
                    })
                }
            }
        }
    }
}

LOGS

Error Domain=FIRAuthErrorDomain Code=17004 "Unsuccessful debug_token response from Facebook: {"error":{"message":"(#100) The App_id in the input_token did not match the Viewing App","type":"OAuthException","code":100,"fbtrace_id":"BwV3jZweRqo"}}" UserInfo={NSLocalizedDescription=Unsuccessful debug_token response from Facebook: {"error":{"message":"(#100) The App_id in the input_token did not match the Viewing App","type":"OAuthException","code":100,"fbtrace_id":"BwV3jZweRqo"}}, error_name=ERROR_INVALID_CREDENTIAL}

WHAT I'VE TRIED

  1. Info plist has correct FacebookAppID and AccountKitClientToken
  2. Tried both ON / OFF for "Require App Secret" in Facebook settings
  3. OAuth redirect URI from Firebase added to Facebook settings
2 Answers

This was ridiculously hard to find. I had to go to Firebase > Authentication > Sign-in Method > Facebook and change the fields in there to match those on Facebook developer. For some inexplicable reason they were different...

If you're using expo with React Native, this might save you some time. Because at the moment, Facebook Login on iOS can only work with standalone apps.

Related