Setting $GOOGLE_APPLICATION_CREDENTIALS is causing authentication issue
shuchenliu opened this issue · comments
Will commented
- Operating System version:
macOS 12.4
- Firebase SDK version:
firebase cli 12.5.2
- Firebase Product:
admin 11.10.1
- Node.js version:
v18.16.0
- NPM version: 9.5.1
Steps to reproduce:
When pointing $GOOGLE_APPLICATION_CREDENTIALS to a JSON key and running firebase emulators:start --only functions
, the console will confirm the key is recognized
functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to
<absolute-path-the-key-file>.json. Non-emulated services will access production using these credentials. Be careful!
but the firebase-admin
module will throw error
FirebaseAppError: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".
...
errorInfo: {
code: 'app/invalid-credential',
message: 'Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".'
},
When passing in the same key file directly when initializing firebase-admin
, no such error is produced.
Relevant Code:
initialization that WILL cause the error (with $GOOGLE_APPLICATION_CREDENTIALS
set to the path to the key JSON file)
admin.initializeApp();
// or
admin.initializeApp({
credential: admin.credential.applicationDefault(),
});
initialization that will NOT cause the error:
const serviceKey = require("path-to-the-key.json");
admin.initializeApp({
credential: admin.credential.cert(payload)
});
code snipet to trigger the error
async function test() {
const EMAIL = <redacted@redacted>;
const user = await admin.auth().getUserByEmail(EMAIL);
}
Google Open Source Bot commented
I found a few problems with this issue:
- I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
- This issue does not seem to follow the issue template. Make sure you provide all the required information.