title: 'auth/invalid-api-key' When Letting the Admin SDK discover a service account
body: <p>In different pages of the Firebase Admin SDK documentation, e.g., <a href="https://firebase.google.com/docs/auth/admin/create-custom-tokens#letting_the_admin_sdk_discover_a_service_account" rel="nofollow noreferrer">this page</a>, it is suggested that:</p>
  
  <blockquote>
    <p>If your code is deployed in an environment managed by Google, the
    Admin SDK can attempt to auto-discover... the service account
    provisioned for your app...To make use of these signing methods,
    initialize the SDK with Google Application Default credentials and do
    not specify a service account ID string: <code>admin.initializeApp();</code></p>
  </blockquote>
  
  <p>When I do this, I get the following error message:</p>
  
  <blockquote>
    <p>[Error: Your API key is invalid, please check you have copied it
    correctly.]   code: 'auth/invalid-api-key',   message: 'Your API key
    is invalid, please check you have copied it correctly.'</p>
  </blockquote>
  
  <p>Note that I do not get this error message when I manually download and import the credentials and service account JSON files in my project.</p>
  
  <p>Detailed information for reproduction of the error:
  1- I'm deploying this on Cloud Functions using Firebase CLI. So, basically, I use <code>firebase deploy</code>.</p>
  
  <p>2- Here is the minimal code in my Node.js App:</p>
  
  <pre><code>const admin = require("firebase-admin");
  const config = require("./firebase-config");
  admin.initializeApp();
  
  const firebase = require("firebase");
  firebase.initializeApp(config);
  
  const functions = require("firebase-functions");
  const express = require("express");
  const bodyParser = require("body-parser");
  
  const app = express();
  app.use(bodyParser.json());
  
  const cors = require("cors");
  app.use(cors());
  
  app.get("/", Some_Function);
  
  exports.api = functions.https.onRequest(app);
  </code></pre>
  
  <p>The error happens when I replace <code>firebase.initializeApp(config);</code> with <code>firebase.initializeApp();</code></p>