12

i am developing a serverless client app that uses Firebase authentication and other services from Google. It was all working nicely, when suddely the FB login authentication stopped working. It happens that when try to login the user i obtain a 400 BADREQUEST with the following body:

{
    "error": {
        "code": 400,
        "message": "API key expired. Please renew the API key.",
        "errors": [{
            "message": "API key expired. Please renew the API key.",
            "domain": "global",
            "reason": "badRequest"
        }],
        "status": "INVALID_ARGUMENT"
    }
}

The url causing the problem is:

https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectConfig?key=AIzaSyDXJ1Lwo_Md0xZzFfPX9Y8dQWOaODE4uiM&cb=1534851951010

Some weird things:

  • i tested with totally different projects (so brand new keys): still failing
  • if i go to cloud console i found several unrestricted keys automatically created by Google (i attach a screenshot)

enter image description here

I also created a brand new app and executed it locally. Same outcome.

Any ideas ?

Add: i have just discovered that the Identity API is effectively returning me 100% failures at the moment.

enter image description here

Bruno Ripa
  • 833
  • 2
  • 12
  • 25
  • Try creating a new `browser` API key. – bojeil Aug 22 '18 at 07:18
  • Apparently there was an error with a key; support has fixed it but i escalated it because i have not understood what the problem was. I'll update the answer as soon as i have new info. – Bruno Ripa Aug 24 '18 at 08:27
  • 1
    I'm getting this all of a sudden too... Any news? – arao6 Aug 27 '18 at 02:54
  • Hi, not yet. As i stated in the previous comment, 'a key expired', but if you followed the project docs there's nothing to be created explicitly and also no manual key management is supposed to happen, so i escalated and i am waiting from the support. This needs to be understood if we want to go live with solutions built on top of Firebase. – Bruno Ripa Aug 27 '18 at 06:27
  • Final update. According to the customer support, a key has been effectively deleted. Now, i don't remember such an action, and i also think that it must be properly clear what is happening when you are doing it. Anyway, for the records, if you might be experiencing the same problem i had, remember to inspect the keys. – Bruno Ripa Sep 22 '18 at 09:40
  • @BrunoRipa so what was your solution? I'm having the same problem and can't figure out how to fix that – vir us Sep 22 '18 at 14:57
  • @virus basically i report here the response: ``` Upon checking your project API keys, it seems the one you're using in the link provided (REDACTED) is no longer exists. It may be deleted, because I've seen the newly created Server and Browser key. With this, I changed the key parameter using the new Server key [0] and it's working fine now. ``` If you read it like this, it might look obvious, but i have no real fre flag in my mind of any relation between server/browser keys and the code that firebase requires to get configured. The last statement if pretty obscure, anyway. – Bruno Ripa Sep 25 '18 at 10:49
  • Time passed, anyway, so i have not replied to it. – Bruno Ripa Sep 25 '18 at 10:50
  • Ok thanks @BrunoRipa. Hopefully the firebase support will be able to fix that for me as well as I'm still not able to do it on my end. – vir us Sep 26 '18 at 00:13
  • WARNING!! You should never expose your API keys in public like this!! I did once (I accidentally backed up my google-services.json file to my GitHub) and it was hijacked and used for "mining cryptocurrency"!... My project was suspended as a result. Although I got it back after contacting support... but no fun experience. :p – Karolina Hagegård Feb 25 '21 at 08:31
  • No worries, those were no more valid ;-). Thanks anyway – Bruno Ripa Feb 25 '21 at 12:02

10 Answers10

19

I was able to get this issue as well and this helped me solve my issue:

  1. Go to google api console and find the key: Android key (auto created by Google Service). These keys are automatically generated by Firebase when you choose the option: Email/password in authentication. Copy that key.

  2. Go to the google-services.json in your android studio under the projects section. Click on the file and look for the api_key -> current_key. Modify that value with the api key in step 1.

Ziggy
  • 491
  • 1
  • 6
  • 17
  • 4
    I did the same and it didn't work. I then also did run a "Clean Project" on Android studio and it worked! At last. Thanks for solution! – Nick Dec 05 '19 at 16:23
  • @Nick "Clean Project" before compiling the apk is the right key. thanks – GPack Mar 30 '20 at 15:34
3

I had the same problem, i fixed it by: Resetting my project, which included... Deleting the Google-Services.json file, replacing the SHA1 key, syncing and adding the new Google-Services.json file on my project. hope it helps you.

Cheers

Doilio Matsinhe
  • 2,131
  • 16
  • 29
2

I Was able to resolve the issue by going into my firebase project settings> General> update my old API key with the Web API key value.

OsamaD
  • 453
  • 7
  • 12
1

First, go to https://console.firebase.google.com/

  1. Then choose the Android project

  2. Then go to SETTINGS of that project

  3. First, check that: sha1 and sha256 fingerprint are there for debug apk (Necessary) and release apk (necessary if you create a signed apk)

  4. There you will see a download JSON file button, click on it, and download the file.

  5. Then go to Android Studio and OPEN your project.

  6. Then on the left side menu, click the project subfile then find the googleservices.json file.

  7. Open that file by double-clicking it

  8. Now open the downloaded file, googleservices.json, and open it in notepad.

  9. Now copy all the content, just select all, and copy.

  10. Now go to the Android Studio, and right-click on the Google services file (in IntelliJ) and click compare with the clipboard and carefully accept all the differences into the Android Studio file.

  11. Or you can directly remove all the content and paste the copied into the Android Studio JSON file.

DONE! NOTE: Make sure you make a copy of the file before doing this.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Vijay
  • 1,163
  • 8
  • 22
0

Open the Firebase Console. Go to the Project Settings -> General Tab -> Your Web API Key Would have been Updated Automatically. Then Copy that API Key and replace it with API key in your environment.ts File and it will be Working.

Hope it Helps You!

0

In my case, Android Studio hasn't correctly generated string.xml based on the updated data in google-services.json, so when I replaced the old API key manually, it finally worked.

Jakub Kostka
  • 551
  • 2
  • 7
  • 20
0

AngularFire, Ionic, Angular

I got the new API key from Browser key (auto-created by Firebase) in Google cloud console and replace it:

environment.prod.ts

 firebaseConfig: {
          apiKey: 'here'
    }

and also D:\me\my-mobile\android\app\google-services.json

 "api_key": [
        {
          "current_key": "here"
        }

Now it is working fine.

Sampath
  • 63,341
  • 64
  • 307
  • 441
0

I was able to clear this issue by the following steps:

  1. This is happening because of the expired Web- API key in firebase. So open your project console.
  2. Move to your project settings
  3. Grab the Web-API key over there
  4. Open your flutter project and move to google-services.json file
  5. replace the current-key value with the new copied API key.
  6. Or simply replace old google-services.json file with newly downloaded one which is present in the same project settings.
  7. Run flutter clean in your project terminal
  8. Run flutter pub-get to get dependencies
  9. Rebuild your app and done.
Andronicus
  • 25,419
  • 17
  • 47
  • 88
0

Go to your google cloud platform, Goto API credentials and compare your downloaded google services JSON from Firebase with what's in the API credentials of GCP.

It can so happen that youre using a wrong ClientID or API key in your JSON.

Cheers

0
Hi All if you are getting this error:

error: Error [firebase_auth/internal-error] {"error":{"code":400,"message":"API key not valid. Please pass a valid API key.","errors":[{"message":"API key not valid. Please pass a valid API key.","domain":"global","reason":"badRequest"}],"status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"API_KEY_INVALID","domain":"googleapis.com","metadata":{"service":"identitytoolkit.googleapis.com"}}]}}


this means you are trying to run app on web chrome and in your flutter app this is not configure so follow below steps:

 1. Go to https://console.firebase
 2. Select your project name i.e. "E-Commerce App"
 3. Select Add App option from dashboard select platform (flutter/android/ios/web) from this select flutter
 4. Add Firebase to your Flutter app this screen will open then select next
 5. From any directory, run this command:"dart pub global activate flutterfire_cli"
 6. Then, at the root of your Flutter project directory, run this command:"flutterfire configure --project=eshop-a44ca"
 7. After "flutterfire configure" check npm

add this in main.dart file: 
await Firebase.initializeApp(
         options: DefaultFirebaseOptions.currentPlatform,
     );

 8. Run this command in your project directory npm install -g firebase-tools
9.Again run this command ""flutterfire configure --project=eshop-a44ca" you will see below screen [firebase options file created in lib folder]


 9. now you can sign up/register user successfully 
 10. [user created on firestore database ]


  [1]: https://i.stack.imgur.com/NBiDz.png