Firebase for iOS, Invalid API Key

Puthnith
3 min readDec 10, 2016

--

Firebase by Google

Firebase, owned by Google, is currently becoming the most popular cloud-hosted NoSQL/JSON database these days and there are a ton of tutorials from blog posts to YouTube videos. You can learn the basic for free 😎 (when you know the basic, you can go through advanced stuffs by yourself, right? 😆)

This medium is not gonna teach you how to use Firebase but to show you a common bug in Firebase. (Correct me if I’m wrong!)

An invalid API Key was supplied in the request.

Usually, we don’t want to face any problem which is not addressed in tutorials during the state of learning. This is known as demotivation.

Well, enough talk!

TL;DR

re-download the `GoogleService-Info.plist` file

Firebase Authentication

To use Firebase in your iOS project, you first need to create a Firebase project and add your iOS app (the bundle ID) to it. Then, you’re required to add `GoogleService-Info.plist` to the iOS project and pod the Firebase frameworks.

Now, I assume you set up everything as instructed such as `FIRApp.configure()` and you’re ready to write some authentication code with Firebase using password-based accounts.

Creating a user using password-based accounts

Problem

When you run the app and you may get this error:

FIRAuthErrorDomain: An invalid API Key was supplied in the request.
Optional(Error Domain=FIRAuthErrorDomain Code=17023 "An invalid API Key was supplied in the request." UserInfo={NSLocalizedDescription=An invalid API Key was supplied in the request., error_name=ERROR_INVALID_API_KEY})

The problem is `GoogleService-Info.plist` file doesn’t have `API_KEY` item. If you google around, you may get many answers and one of them is to set up a API key and add it to the PLIST file.

Don’t do that! You may end up with another error.

FIRAuthErrorDomain: An internal error has occurred, print and inspect the error details for more information.
An internal error has occurred, print and inspect the error details for more information.Access Not Configured. Google Identity Toolkit API has not been used in project xxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/identitytoolkit/overview?project=xxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

This is because the given API key is not from the Firebase project.

Note that it’s not Web API Key either.

Solution

To fix the issue, all you need to do is to re-download the `GoogleService-Info.plist` file and replace with the one inside your iOS project. You will see there is an `API_KEY` item in the new PLIST file.

To download the file again:

  1. go to Firebase project Overview
  2. click on ⠇(three vertical dots) of the iOS app and choose Manage
  3. Scroll down and you will see a button to download the PLIST file

Conclusion

This tiny issue should be fixed at the first place. For beginners, it’s such a troublesome. However, I hope this medium is helpful.

Bonus

Code snippets for Firebase using password-based accounts

If you find this medium useful, please ❤️💛💚💙💜 as much as you can!

Until next time! 🙃

--

--