如何使用signInWithCredential()
代替signInWithPopup()
。 signInWithPopup
我的移动电话谷歌chromes浏览器没有工作,我已经检查过,发现这是一个已知问题,而是使用signInWithCredential()
代替。但是我似乎无法使用它,我使用signInWithPopup()
的当前代码如下。任何善良的灵魂都可以帮助我?感谢
login() {
return new Promise((resolve) => {
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()).then(() => {
this.afAuth.authState.take(1).subscribe(async (authState) => {
resolve(authState);
});
});
});
}
答案 0 :(得分:0)
要使用signInWithCredential
,您需要使用OAuth ID令牌/访问令牌初始化AuthCredential。
例如:
const cred = firebase.auth.GoogleAuthProvider.credential(googleIdToken, googleAccessToken);
firebase.auth().signInAndRetrieveDataWithCredential(cred)
.then(userCredential => {
// Success.
})
.catch(error => {
// error occurred.
});
您可以使用Google登录库获取Google ID令牌:https://developers.google.com/identity/sign-in/web/sign-in
这仅适用于浏览器。如果您在其他非浏览器环境中使用此功能,则需要一些第三方OAuth库才能获得相应的OAuth凭据。