Getting "Error: Invalid IdP response/credential" trying to add FB user on Firebase Auth list

Getting "Error: Invalid IdP response/credential" trying to add FB user on Firebase Auth list

我一直致力于在基于 Expo 的应用程序中实现 Facebook 和 Google 登录方法。

将 Firebase 连接到我的应用程序后,我希望用户列在 Firebase 用户中。虽然 Google 登录似乎工作正常,但 Facebook 给出了如下所述的错误 firebase.auth().signInWithCredential(credential):

[Error: Invalid IdP response/credential: http://localhost?id_token=EAAGUBzIZAgb0BABAkdrj5NcUcvljcsLeNBQlV5VUZAZC7M8e7sSRg2MkqlFCuD7tKjin4uZBep5gSs20oAo8fXKiUqq2deEbUl6HoaAUskTda7x49VCqqcbYh1W3566fMZBtRFB5S3fRV7D41AGVGPMAck91l1KiFCzQzCGtSf5g6ZBKoyHw03LOVONcOiwVZB4vXVcGPYmIzL3RuzzztdBNLRql5ndSk0ZD&providerId=facebook.com] 

这是代码的相关部分

  1. Firebase.js
// imports, configs and exports omitted
export const facebookProvider = new firebase.auth.FacebookAuthProvider;
  1. LoadingScreen.js(签到部分)
import firebase, { googleProvider, facebookProvider } from "../firebase";
import * as Facebook from "expo-facebook";

const LoadingScreen = ({ navigation }) => {
  const signInWithFacebook = async () => {
    try {
      await Facebook.initializeAsync("444233602924989");
      const { type, token } = await Facebook.logInWithReadPermissionsAsync(
        "444233602924989",
        {
          permissions: ["public_profile", "email"]
        }
      );
      if (type === "success") {
        const credential = facebookProvider.credential(token);
        onSignInFB(credential);
      } else {
        Alert.alert('FB sign-in failed')
      }
    } catch ({ message }) {
      console.log(`Facebook 1 Error: ${message}`);
      Alert.alert(`first ${message}`);
    }
  };

  const onSignInFB = credential => {
    firebase
      .auth()
      .signInWithCredential(credential)
      .then(function() {
        navigation.navigate("Home");
      })
      .catch(function(error) {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        // The email of the user's account used.
        var email = error.email;
        // The firebase.auth.AuthCredential type that was used.
        var credential = error.credential;
      });
  };
};

我已经记录了一些元素如下:

    Object {"oauthIdToken": "EAAGUBzIZAgb0BAKgeMa5E7qHm8WNJYv5SeuQ8DHyhkUlAnkMhE7niu6tx3e2amSMHSEqG9B0MV4a9dygwgjs337PR7AA3M4PZB2F6x6n1FwAEyZBKhZBpOSE2OWQ9dJipirpafg61TKX36hnKIzaIcwRkjs8YYRBbDuLnZAhJzWst3ZBM5tafwxYKumv2F4kYdexxZAXqb1nosnwYodNvB9bstkcaBrfB8ZD",
      "providerId": "facebook.com",
      "signInMethod": "facebook.com",
    }

我还查看了我自己的可能错误清单,但找不到任何错误:

如果能找出问题的根源就好了! (一种可能是从 logInWithReadPermissionsAsync 返回的访问令牌与 credential 对象中的 oauthIdToken 属性 相同,但我没有手动放置或更改任何一个那些。)

感谢阅读:)

我今天对此表示反对,解决方案是将一个对象传递给 credential 调用,尽管文档说要传递一个字符串。此外,对象 属性 需要键入 accessToken.

所以不是: const credential = facebookProvider.credential(token);

尝试: const credential = facebookProvider.credential({ accessToken: token });

根据文档,我不知道为什么需要该密钥或为什么它必须是一个对象,但它适用于我的情况。希望对您有所帮助!