我有以下代码,用于重新认证用户:
checkAccountPassword(password) {
if (this.isFirebaseUserLoggedWithFacebook()) {
return this.afAuth.auth.currentUser.reauthenticateAndRetrieveDataWithCredential(firebase.auth.FacebookAuthProvider.credential(facebookToken - WHERE_CAN_I_FIND_THIS_TOKEN?????));
}
return this.afAuth.auth.currentUser.reauthenticateAndRetrieveDataWithCredential(firebase.auth.EmailAuthProvider.credential(firebase.auth().currentUser.email, password));
}
然后我可以删除用户(因为删除需要最近的身份验证)。
问题是-无法获得令牌,我需要重新认证FB用户。
我有可以获取令牌的代码,但是以防万一,当用户安装了Facebook应用程序时,但是如果用户使用弹出窗口登录Facebook,我不知道在哪里可以获取facebookToken
doFacebookLogin() {
if (this.platform.is('cordova')) {
return from(this.fb.login(['email', 'public_profile'])).pipe(
switchMap(response => {
this.currentFacebookCredential = firebase.auth.FacebookAuthProvider.credential(response.authResponse.accessToken);
return from(firebase.auth().signInAndRetrieveDataWithCredential(this.currentFacebookCredential));
}),
switchMap(() => {
return this.afAuth.idToken;
}),
first(),
);
} else {
const provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('email');
provider.addScope('public_profile');
return from(this.afAuth.auth.signInWithPopup(provider)).pipe(
switchMap(() => this.afAuth.idToken),
first(),
);
}
}
答案 0 :(得分:0)
我找到了一个解决方案,我需要再次调用doLogin(),然后将对象保存到currentFacebookCredential中,以这种方式进行popup-login情况:
return from(this.afAuth.auth.signInWithPopup(provider)).pipe(
tap(userCred => {
this.currentFacebookCredential = userCred.credential;
}),
switchMap(() => this.afAuth.idToken),
first(),
);