Comments (6)
Hey @glorat, thanks for the detailed report and for sharing your observations. I’ve been trying to reproduce this issue, but so far I haven’t been able to replicate the behavior mentioned. Here’s my current setup for reproducing the issue:
functions/index.js
import * as functions from "firebase-functions/v1"
const FUNCTION_SECRETS = ["FIRST_SECRET"]
export const helloWorld1 = functions
.runWith({ secrets: FUNCTION_SECRETS }).https.onRequest((request, response) => {
response.send("Hello from Firebase!" + process.env.FIRST_SECRET);
});
export const processUploadedFile = functions
.runWith({ secrets: FUNCTION_SECRETS })
.storage.object()
.onFinalize(() => {
functions.logger.debug(`The first secret is ${process.env.FIRST_SECRET}`)
})
functions/.secret.local
FIRST_SECRET=local-secret-first
No errors were raised running firebase emulators:start --project demo-project
as well as when invoking the functions.
Just to verify, are you using defineSecret
in your codebase? I found a similar issue that could be related #5520, and I tried adding defineSecret
to my codebase and I was able to get the same error message you shared:
functions: Failed to load function definition from source: FirebaseError: HTTP Error: 401, Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
from firebase-tools.
Just to verify, are you using
defineSecret
in your codebase? I found a similar issue that could be related #5520, and I tried addingdefineSecret
to my codebase and I was able to get the same error message you shared:functions: Failed to load function definition from source: FirebaseError: HTTP Error: 401, Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
Hi, yes you need to have defineSecrets in the codebase and a function that depends on that secret to cause this issue (e.g. .runWith({ secrets: FUNCTION_SECRETS })
My workaround also addresses #5520 , per my local testing. My proposed fix should also be good
from firebase-tools.
Thanks for the additional information @glorat. I’ll raise this to our engineering team so they can take a look. Also, it looks like you have a potential fix for this, feel free to make a PR if you feel up for it! Contributions are always welcome!
from firebase-tools.
Thanks for the additional information @glorat. I’ll raise this to our engineering team so they can take a look. Also, it looks like you have a potential fix for this, feel free to make a PR if you feel up for it! Contributions are always welcome!
Unfortunately, I couldn't figure out how to make my hardcoded approach generic and I can't quite infer the design so not confident to PR it. My direction to the dev team is to look at resolveParams
in params.ts
. It already excludes .env related params from the secrets manager check so one just needs to extend that the secrets.local exclusion too. However, it's not clear how to do that. Options include
- Just try to read it right there in that function
- Get it passed it like UserEnvs already does
- Refactor and reuse the existing .secret.local loading code in the main emulator
I think I'll need to leave that with the devs to decide.
from firebase-tools.
@glorat I am also facing this issue, can you share your hardcoded solution? I would like to see it if possible, I am currently adding a TEST env var to firebase command, TEST=true firebase emulators:exec vitest
then added a break in the loop in params.js:
for (const param of needSecret) {
if (process.env.TEST) {
break;
}
await handleSecret(param, firebaseConfig.projectId);
}
Works for now for me but keen to see another solution to compare. Thanks
from firebase-tools.
@glorat I am also facing this issue, can you share your hardcoded solution? I would like to see it if possible, I am currently adding a TEST env var to firebase command,
TEST=true firebase emulators:exec vitest
then added a break in the loop in params.js:for (const param of needSecret) { if (process.env.TEST) { break; } await handleSecret(param, firebaseConfig.projectId); }Works for now for me but keen to see another solution to compare. Thanks
That's the way to go. This is best since you're happy to modify a local copy.
An alternative is to set secrets through environment but if you do this be careful not to deploy functions from command line and send the environment to the cloud.
from firebase-tools.
Related Issues (20)
- Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html" HOT 3
- firebase_storage eternal await in useStorageEmulator Flutter HOT 1
- Firebase Login Error HOT 4
- Is `GOOGLE_VENDOR_NPM_DEPENDENCIES` supported for functions deploys?
- Datastore emulator reset does not work HOT 2
- Datastore emulator enforcing indexes when docs say it doesn't HOT 2
- Web Frameworks Support for Angular 18
- NextJS Link issue when hosted on Firebase Hosting HOT 3
- deploy with remix, verify with truffle
- Cant deploy important update because of this ERROR!! -- Error: Cloud Runtime Config is currently experiencing issues, which is preventing your functions from being deployed. Please wait a few minutes and then try to deploy your functions again. HOT 1
- firebase CLI auth error in 13.13.1 HOT 14
- 4 out of 13 builds fail with: Build failed with status: EXPIRED and message: An unexpected error occurred HOT 7
- Firebase deploy error. Container import failed HOT 2
- Hello, im currently developing a flutter app using firebase functions im using python but it doesnt support authentication triggers HOT 1
- Missing "version" data with non transactional commits HOT 3
- If the pubsub function is implemented in 2gen, the publishTime is 1970/01/01 00:00:00. HOT 1
- Tool commands 'logout' and 'login --reauth' fail when credentials are expired in [email protected] HOT 3
- Astro / Node / Firebase Hosting - API Values returned not valid JSON HOT 3
- Cannot authenticate/reauthenticate/logout with v 13.13.2 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-tools.