问题
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
- Info plist has correct FacebookAppID and AccountKitClientToken
- Tried both ON / OFF for "Require App Secret" in Facebook settings
- OAuth redirect URI from Firebase added to Facebook settings
回答1:
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...
来源:https://stackoverflow.com/questions/56712711/login-through-facebook-using-oauth-issue-with-firebase-app-id-in-the-input-toke