Description
Environment
- Operating System version: Fedora Linux 40
- Firebase SDK version: 6.0.1
- Firebase Product: auth, tasks, emulator
- Node.js version: 18
- NPM version: 10.2.3
- Firebase Tools: 13.23.1
Problem
Authentication fails in the firebase tasks emulator on
await queue.enqueue(...) \\ full sample below
with the following error:
Error scheduling task 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".
We were able to reproduce the bug reported here firebase/firebase-tools#7821 with the latest SDK and firebase tools versions.
The error does not occur when application default credentials are available and is thus easily overlooked.
Steps to reproduce:
- Setup firebase project as in Cloud Tasks Emulator Error:
Error fetching access token: invalid_grant (reauth related error (invalid_rapt))
firebase-tools#7821. - Start the emulator with the code below.
npm run build && npx firebase emulators:start --project='demo-project' --debug
- Enqueue a task by executing the
testOnRequest
function (http://127.0.0.1:5001/demo-project/us-central1/testOnRequest
).
Relevant Code:
Reproducible example that is even more minimal than in the mentioned issue:
import { onRequest } from "firebase-functions/v2/https";
import { getFunctions } from "firebase-admin/functions";
import { onTaskDispatched } from "firebase-functions/v2/tasks";
import * as logger from "firebase-functions/logger";
import { initializeApp } from "firebase-admin/app";
// Initialize the Firebase app
initializeApp()
// The http function
export const testOnRequest = onRequest(async (request, response) => {
const taskPayload = {
foo: "bar",
};
const taskFunctionName = `testOnTaskDispatched`;
const queue = getFunctions().taskQueue(taskFunctionName);
try {
await queue.enqueue(taskPayload);
response.send("Success. Hello from HTTP onRequest!");
} catch (error) {
console.error("Error scheduling task", error);
response.status(500).send("Error scheduling task");
return;
}
});
// The task function
export const testOnTaskDispatched = onTaskDispatched( (request) => {
logger.info("Success. Hello logs from TASKS onTaskDispatched!", {
foo: request.data,
});
});