Firebase身份验证的最新更改。 Google登录? [英] Recent changes with Firebase Authentication via. Google Sign-In?
问题描述
我向使用Firebase Google登录身份验证的用户提出了一个问题:
I've a question to people who use Firebase Google Sign-In authentication:
我的应用已经使用了几个月,正在使用用于Firebase身份验证的Google登录和电子邮件/密码选项。然而大约一周前,我注意到Google登录已停止工作。没有代码被更改,电子邮件/密码选项也像往常一样工作。
My app, which has already been working for a couple of months, is using both Google Sign-In and e-mail/password options for Firebase Authentication. However about a week ago I've noticed that the Google Sign-In stopped working. No code was changed, also the e-mail/password option works just as usual.
我检查了文档( https://firebase.google.com/docs/auth/android/google-signin ),它仍然是相同(我的应用程序从文档中复制身份验证方法)。
I've checked the documentation (https://firebase.google.com/docs/auth/android/google-signin), it's still the same (My app copies the authentication method from the documentation).
您是否也面临过类似的问题?如果是,请告诉我如何解决。
Did you face a similar problem too? If yes, please tell me how can I solve it.
以下是我在LoginActivity中与Google登录相关的代码:
Here is my code related to Google Sign-in inside my LoginActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
...
//--------Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Toast.makeText(LoginActivity.this, "Connection failed!", Toast.LENGTH_SHORT).show();
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleBttn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SignIn();
}
});
}
private void SignIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mProgress.setMessage("Signing in with Google Account...");
mProgress.show();
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
// Google Sign In failed, update UI appropriately
// ...
mProgress.dismiss();
Toast.makeText(LoginActivity.this, "Google sign in failed!", Toast.LENGTH_SHORT).show();
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
mProgress.dismiss();
checkUserExist();
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
private void checkUserExist() {
final String user_id = mAuth.getCurrentUser().getUid();
mDatabaseUsers.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild(user_id)) {
Intent mainIntent = new Intent(LoginActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mainIntent);
} else {
Intent setupIntent = new Intent(LoginActivity.this, SetupActivity.class);
setupIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(setupIntent);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
这是我的app和项目级build.gradle文件: https://gist.github.com/anonymous/2c9737e898ca2568129af63e61a30f16
Here are my app and project level build.gradle files: https://gist.github.com/anonymous/2c9737e898ca2568129af63e61a30f16
推荐答案
好的,我承认一件事 - 它与代码无关......我设法解决了这个问题,我将解释如何。
Okay, I'll admit one thing - it had nothing to do with the code... I managed to fix the issue, and I'll explain how.
我使用调试器调试了应用程序,因为我在评论中被好人推荐,结果发现在onActivityResult()方法中,Auth.GoogleSignInApi.getSignInResultFromIntent(data)返回此错误结果代码:
I debugged the app with the debugger as I was recommended by good people inside the comments and it turned out that inside the onActivityResult() method the Auth.GoogleSignInApi.getSignInResultFromIntent(data) was returning this error result code:
状态{statusCode = DEVELOPER_ERROR,resolution = null}
Status{statusCode=DEVELOPER_ERROR, resolution=null}
这足以让我们了解在哪里挖掘。我查看了我的Firebase控制台 - >项目 - >项目设置 - > SHA-1指纹。
This was more than enough to understand where to dig. I looked up into my Firebase console -> Project -> Project settings -> SHA-1 fingerprints.
有趣的是 - 那里有指纹,我是指纹放在前面。无论如何,我决定检查它是否与我从Android Studio获得的相同 - > Gradle Projects - >在project / app / tasks / android /文件夹中有一个包含SHA-1的signingReport。令我惊讶的是,SHA-1指纹不匹配。无论如何,我从AS复制了它并在Firebase Console中添加了第二行。你猜怎么着?它现在有效...
What is interesting - there was a fingerprint there, the one I've put before. Anyways, I decided to check if it's the same with the one I get from Android Studio -> Gradle Projects -> inside the project/app/tasks/android/ folder there is a signingReport which contains SHA-1. To my surprise, the SHA-1 fingerprints did not match. Anyways, I copied it from the AS and added 2nd line inside Firebase Console. Guess what? It works now...
我仍然有很多关于为什么会发生这种情况的问题,因为它确实突然发生,正如我之前在我的问题中所解释的那样。
I still have a lot of questions about why this could happened, since it did happen all of a sudden as I explained previously in my question.
我希望这些信息可以帮助其他有类似问题的人。然而,问题已经解决了,但是因为有一个赏金集我将奖励给那个人,他会向我解释这个魔法......
I hope this info will help others who had a similar issue. Nevertheless, question solved, but since there is a bounty set I'll award it to the person, who'll explain me this magic...
这篇关于Firebase身份验证的最新更改。 Google登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!