Solution 1 :
Although it’s good that API Keys are set to expire, I hadn’t realized that Firebase sets the API Keys that it creates to expire (yearly) until I investigated after reading your question.
If you haven’t seen this, please see … managing API keys for Firebase
You can view API keys for a project two ways:
- Firebase Console, select your Project, click the ‘gear’ icon next to “Project Overview” and then “Project Settings”.
- Cloud Console, select your Project, then “APIs & Services” and then choose “Credentials”.
The documentation doesn’t appear to cover the renewal process.
I suspect (!?) that you can use e.g. Cloud Console, find the correct API Key and click “REGENERATE KEY”.
Then you will need to revise all occurrences of this API Key in your distributed (!) code.
For example, I’m only using Web clients and I have:
const firebaseConfig = {
apiKey: "[[HERE]]",
authDomain: "...",
projectId: "...",
storageBucket: "..",
messagingSenderId: "...",
appId: "..."
};
I assume (!?) there’s an equivalent config for Android apps.
Solution 2 :
Glad to inform you that the issue has been resolved. The troublemaker was an old version of the “google-services.json” in the “Build” folder. Removing and replacing it with the updated version of “google-services.json” worked like a charm.
Problem :
I am developing an Android app and trying to implement a Google sign-in functionality. The authentication info that it’s supposed to produce, is stored in my Firebase database. It seemed to have worked until recently.
I have been trying to resolve this frustrating exception in many ways:
- I regenerated an API key on GCP, redownloaded google-services.json and rebuilt the project.
- I noticed that the API key specified in the values.xml file (this file is stored in appbuildgeneratedresgoogle-servicesdebugvalues) is outdated. Therefore, I tried to modify the fields “google_api_key” and “google_crash_reporting_api_key”, as well as delete the file itself. The outdated data appears as soon as I rebuild the project.
- I made sure that the SHA-1 is specified in the Firebase console
- I set the API key’s restrictions using GCP
Google sign-in code:
private void loginUserWithGoogle() {
GoogleSignInOptions gsio = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getOwnerActivity().getString(R.string.default_web_client_id))
.requestEmail()
.build();
GoogleSignInClient gsic = GoogleSignIn.getClient(getContext(), gsio);
Intent sii = gsic.getSignInIntent();
getOwnerActivity().startActivityForResult(sii, GOOGLE_SIGN_IN_REQUEST_CODE);
}
public void credentialsFromGoogleIntent(@Nullable Intent data) {
Task<GoogleSignInAccount> accountTask =
GoogleSignIn.getSignedInAccountFromIntent(data);
accountTask.addOnCompleteListener(receiveAuthInfo -> {
if (receiveAuthInfo.isSuccessful()) {
GoogleSignInAccount account = accountTask.getResult();
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
auth.signInWithCredential(credential).
addOnCompleteListener(completeSignIn -> {
if (!completeSignIn.isSuccessful()) {
Log.w("LoginWindow", "signInWithCedential:Failure", completeSignIn.getException());
return;
}
CollectionReference reference = db.collection(USER_COLLECTION);
FirebaseUser user = auth.getCurrentUser();
Query query = reference.whereEqualTo("uuid", user.getDisplayName());
query.get().addOnCompleteListener(task -> {
if (task.getResult().size() <= 0) {
UserProfileChangeRequest.Builder build = new UserProfileChangeRequest.Builder();
String userId = UUID.randomUUID().toString();
build.setDisplayName(userId);
Task<Void> task1 = user.updateProfile(build.build());
Map<String, Object> userData = new HashMap<>();
userData.put("uuid", userId);
userData.put("password", "irrelevant");
Task<DocumentReference> task2 = reference.add(userData);
Tasks.whenAll(task1, task2).continueWith(taskContinue -> {
Intent intent = new Intent(getOwnerActivity(),
MainActivity.class);
getOwnerActivity().startActivity(intent);
return null;
});
} else {
Intent intent = new Intent(getOwnerActivity(),
MainActivity.class);
getOwnerActivity().startActivity(intent);
}
});
});
} else
Log.w("LoginWindow", receiveAuthInfo.getException().toString());
});
}
Comments
Comment posted by Natanoy
Actually, I have already regenerated the API key several times and updated the google-services.json file that’s included in my project subsequently. The exception remains the same. Is there another solution to this issue that you can think of?
Comment posted by DazWilkin
What is
Comment posted by DazWilkin
Ah, I guess
Comment posted by Natanoy
The google-services.json is the config file that you mentioned earlier.
Comment posted by docs
Yeah, sorry. I’m unfamiliar with the Android integration but I just read the