问题
So I\'m Stuck on this frustrating issue. I am quite new to Google Auth on Firebase but I done everything the firebase docs instructed in how to integrate the Google SignIn Auth, yet I\'m still receiving this weird Error in the console consisted of two parts:
12-03 11:07:40.090 2574-3478/com.google.android.gms E/TokenRequestor: You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE
and also
Google sign in failed com.google.android.gms.common.api.ApiException: 10:
Before Anyone attempts to point out similar questions that have previously been asked on stack overflow, Here\'s what I have done till now after seen all the available solutions and yet non has resolved the error
- I have my SHA1 fingerprint for my project
- I have my OAuth 2.0 client ID, both, the android client id and the web client and in the requestIdToken() I have put the web client id.
- I did not publish my project\'s APK on google play store. which means I did not accidentally generate another SHA1 fingerprint.
- I have followed step by step the Google Sign in Auth firebase docs.
here is my code snippet:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
ButterKnife.bind(this);
String webClientId = getString(R.string.web_client_id);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(webClientId)
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
googleLoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try{
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, \"Google sign in failed\", e);
// [START_EXCLUDE]
Toast.makeText(this, \"Gooogle Auth failed\", Toast.LENGTH_LONG);
// [END_EXCLUDE]
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, \"firebaseAuthWithGoogle:\" + acct.getId());
// [START_EXCLUDE silent]
//showProgressDialog();
// [END_EXCLUDE]
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user\'s information
Log.d(TAG, \"signInWithCredential:success\");
FirebaseUser user = mAuth.getCurrentUser();
Toast.makeText(LoginActivity.this, \"Successful Auth\", Toast.LENGTH_LONG).show();
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, \"signInWithCredential:failure\", task.getException());
Toast.makeText(LoginActivity.this, \"Authentication failed.\",
Toast.LENGTH_SHORT).show();
//updateUI(null);
}
// [START_EXCLUDE]
//hideProgressDialog();
// [END_EXCLUDE]
}
});
}
回答1:
Basically problem is in the SHA1 key put on console please regenerate it and put again properly same project.
1)As the answers, make sure that your actual signed Android apk has the same SHA1 fingerprint as what you specified in the console of your Firebase project's Android integration section (the page where you can download the google-services.json)
2)On top of that go to the Settings of your firebase project (gear icon right to the Overview at the top-left area. Then switch to Account Linking tab. On that tab link the Google Play to your project.
回答2:
I was facing the same issue, After checking around for a solution, from regenerating the finger print to linking the app on firebase to the Google play console and publishing the signed apk, the issue was actually because I was using the release SHA-1 on the firebase console.
- If you are still on debut mode, use the debug.keystore SHA1
- Only use the release SHA1 if you are on production mode
https://developer.android.com/studio/publish/app-signing.html
回答3:
When using App Signing by Google Play and Firebase, you need to add the SHA-1 fingerprint of the App signing certificate (found on Google Play Console/ Release Management/ App signing certificate) to the Firebase Console/ Settings/ SHA certificate fingerprints
回答4:
In My case, There is no problem with SHA-1
I have done GoogleAuth using Firebase.
I forgot to add implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
And I put my own key instead of R.string.default_web_client_id, So that was the problem. I added above dependency and replace R.string.default_web_client_id with my own key.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
回答5:
If you have all configuration valid in firebase like SHA-1 and you have imported right google-services.json file still you are getting error then add the support email in firebase console
You have to add support email in fire base console Go to Project-> Setting -> General -> Public setting add Support Email
回答6:
I am not sure if this is the cause, but we might need to use the Web Client ID in the Android App before publishing it, read the following article,
https://android-developers.googleblog.com/2016/03/registering-oauth-clients-for-google.html
回答7:
i was dealing with this problem for 2 days ! the problem was the clientId i used, was android type while i had to use web Aplication type Clientid . please consider this if you have the same problem ;)
回答8:
In my case everything was fine, but error 10 was still happening, what I tried to do was "simple" I called firebase sdk first, like
private val onActivityResultGoogleCode = 1000
private lateinit var mGoogleSignInClient: GoogleSignInClient
private fun mAuth():FirebaseAuth{
return FirebaseAuth.getInstance()
}
public override fun onStart() {
super.onStart()
mAuth().addAuthStateListener(mAuthState())
if(mAuth().currentUser!=null){
// logged
}else{
// You already instantiated 'FirebaseAuth.getInstance()' above SO
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("Cliente_Web")
.requestEmail()
.build()
mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
val signInIntent: Intent = mGoogleSignInClient.signInIntent
rl_google_container_login.setOnClickListener {
startActivityForResult(signInIntent, onActivityResultGoogleCode)
}
}
}
Another solution would be for you to use your KEYSTORE in debug mode.
signingConfigs{
key{
keyAlias 'Alias'
keyPassword 'password'
storeFile file('C:\\Users\\AllanRibas\\AndroidStudioProjects\\tool.jks')
storePassword 'password'
}
}
buildTypes {
debug{
signingConfig signingConfigs.key
}
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
useProguard true
jniDebuggable true
}
debug {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
useProguard true
jniDebuggable true
}
}
来源:https://stackoverflow.com/questions/47619229/google-sign-in-failed-com-google-android-gms-common-api-apiexception-10