我正在尝试使用firebase设置我的react原生应用程序的facebook登录。我正在成功地使用集成的facebook支持与expo的facebook身份验证,并获得一个facebook-token。然而,不幸的是,我在使用这个令牌登录firebase时遇到了一个“无效的IdP响应/凭据”错误。
我已经使用了完全相同的流程(但使用谷歌提供商和令牌)为谷歌登录,并取得了成功。我还能够使用facebook令牌从facebook的rest API中获取显示令牌有效性的数据。
//This function gives the error
doSignInWithFacebookCredential = (facebookToken) => {
const credential = this.facebookProvider.credential(facebookToken);
this.auth.signInAndRetrieveDataWithCredential(credential)
.then(authUser => {
alert("It worked!")
})
.catch(function(error) {
alert(error)
});
}
//Code used to verify facebook token
const response = await fetch(`https://graph.facebook.com/me?access_token=${facebookToken}`);
console.log(await response.json())
//This function works perfectly (The google sign-in with same flow)
doSignInWithGoogleCredential = (googleToken) => {
const credential = this.googleProvider.credential(googleToken);
console.log(credential)
this.auth.signInAndRetrieveDataWithCredential(credential)
.then(authUser => {
alert("It worked!")
})
.catch(function(error) {
alert(error)
});
}
收到有效的facebook令牌后,会发生错误,从而导致catch发出警报
Error: Invalid IdP response/credential: http://localhost?id_token=$facebookToken&providerId=facebook.com
尽管有一个有效的facebook令牌,但facebookProvider.credential(facebookToken)
似乎没有给signInAndRetrieveDataWithCredential()
函数一个有效的令牌,导致了一个‘无效的IdP响应/凭证’错误。
如果有人以前使用过这些方法或有任何建议,我们将非常感谢。
发布于 2019-05-24 07:35:35
如果凭据格式错误或已过期,则抛出,并因此返回无效的idp响应凭据。
由于此方法已弃用,因此我建议使用firebase.auth.Auth.signInWithCredential。而且,也许通过这种方式,无论凭据是否有问题,您都将获得更多详细信息
希望这能有所帮助!
https://stackoverflow.com/questions/56276252
复制相似问题