Android Firebase通过匹配的电子邮件链接多个帐户提供商
在firebase仪表板中,我为一封电子邮件设置了多个帐户 我的应用程序中有简单的电子邮件、Facebook和Google Plus认证 在我的后勤活动中,我会这样处理每一个问题: 谷歌+:Android Firebase通过匹配的电子邮件链接多个帐户提供商,android,facebook,firebase,google-api,firebase-authentication,Android,Facebook,Firebase,Google Api,Firebase Authentication,在firebase仪表板中,我为一封电子邮件设置了多个帐户 我的应用程序中有简单的电子邮件、Facebook和Google Plus认证 在我的后勤活动中,我会这样处理每一个问题: 谷歌+: private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
dialog.dismiss();
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
proceed();
} else {
// If sign in fails, display a message to the user.
Toast.makeText(LoginActivity.this, task.getException().getMessage(),
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
private void handleFacebookAccessToken(AccessToken token) {
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
dialog.show();
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
dialog.dismiss();
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
proceed();
} else {
Toast.makeText(LoginActivity.this, task.getException().getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
}
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
dialog.dismiss();
proceed();
} else {
Toast.makeText(LoginActivity.this, "Wrong email or password", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
}
});
现在出现了令人困惑的问题我如何在getCurrentUser仍然为空时调用它,因为我已跳过使用方法的登录?
文件还说,我处理合并,我不明白
currentUser = auth.signInWithCredential(credential).await().getUser();
此外,signInWithCredenial没有Wait
方法
这意味着我应该在登录后用同一封电子邮件链接多个帐户?要链接帐户,应该有一个现有会话。例如,假设一个新用户使用Google作为身份验证提供者创建了一个帐户 总之,要做到这一点,您需要:
- 使用GIDSignIn向Google验证用户身份李>
- 然后Google返回一个Id令牌(如果一切顺利的话)李>
- 您将使用令牌创建GoogleAuthProvider凭据对象
- 然后使用此凭据在Firebase调用signInWithCredential中进行身份验证
currentUser = auth.signInWithCredential(credential).await().getUser();