firebase / firebase/firebase-admin-node
Setting $GOOGLE_APPLICATION_CREDENTIALS is causing authentication issue
- Lingua principale
- TypeScript
- Stelle
- 1.7k
- Fork
- 419
- Merge medio
- 3g 10h
- PR unite (30g)
- 16
Descrizione
* 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
.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)
``` javascript
admin.initializeApp();
// or
admin.initializeApp({
credential: admin.credential.applicationDefault(),
});
```
initialization that will **NOT** cause the error:
```javascript
const serviceKey = require("path-to-the-key.json");
admin.initializeApp({
credential: admin.credential.cert(payload)
});
```
code snipet to trigger the error
```javascript
async function test() {
const EMAIL = ;
const user = await admin.auth().getUserByEmail(EMAIL);
}
```
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con admin.initializeApp() e admin.credential.applicationDefault(), quindi riproduci il problema con GOOGLE_APPLICATION_CREDENTIALS impostata sul percorso della chiave e confronta con credential.cert(payload). Il lavoro è completato quando l'inizializzazione basata sull'ambiente ottiene un token OAuth valido e admin.auth().getUserByEmail(EMAIL) non genera più l'errore metadata.google.internal segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- authentication
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100