latest : [email protected]
firebase-tools: 6.9.1
Platform: macOS
I upgraded the tools version to the latest.
Since then I am not able to set the port number using firebase serve --only function --port=9000.
So started usingfirebase emulators:start.
Should be able to retrieve the document data from the firestore.
The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
âš Google API requested!
- URL: "https://oauth2.googleapis.com/token"
- Be careful, this may be a production service.
> Auth error:Error: invalid_grant
In a bug they had asked to delete application_default_credential.json from ~/.config/gcloud.
I did that.
After, I got this error:
The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
âš Google API requested!
- URL: "oauth2.googleapis.com/token"
- Be careful, this may be a production service.
> Error: 16 UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See developers.google.com/identity/sign-in/web/devconsole-project.
Both the above scenario happens only when get() is used in the firestore collection or document.
Updated serviceaccountkey.json - did not help
[2019-05-10T04:58:09.087Z] Command: /usr/local/Cellar/node/11.12.0/bin/node /usr/local/bin/firebase emulators:start --debug
[2019-05-10T04:58:09.087Z] CLI Version: 6.9.1
[2019-05-10T04:58:09.087Z] Platform: darwin
[2019-05-10T04:58:09.087Z] Node Version: v11.12.0
[2019-05-10T04:58:09.088Z] Time: Fri May 10 2019 10:28:09 GMT+0530 (India Standard Time)
[2019-05-10T04:58:09.088Z] ----------------------------------------------------------------------
[2019-05-10T04:58:09.099Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2019-05-10T04:58:09.099Z] > authorizing via signed-in user
[2019-05-10T04:58:09.101Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[2019-05-10T04:58:09.101Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token
[2019-05-10T04:58:11.290Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=utf-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 10 May 2019 04:58:11 GMT, server=scaffolding on HTTPServer2, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
[2019-05-10T04:58:11.306Z] >>> HTTP REQUEST GET https://cloudresourcemanager.googleapis.com/v1/projects/travel-wizard-995fa
[2019-05-10T04:58:13.289Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 10 May 2019 04:58:13 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, server-timing=gfet4t7; dur=272, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
i Starting emulators: ["functions"]
✔ functions: Using node@11 from host.
[2019-05-10T04:58:13.309Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/21058201402:getServerAppConfig
[2019-05-10T04:58:15.296Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 10 May 2019 04:58:15 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
✔ functions: Emulator started at http://localhost:9000
i functions: Watching "../gFirebase/functions" for Cloud Functions...
[2019-05-10T04:58:15.654Z] Functions runtime initialized.
[2019-05-10T04:58:15.654Z] Disabled runtime features: undefined
[2019-05-10T04:58:15.987Z] Found google-gax at ../gFirebase/functions/node_modules/google-gax/build/src/index.js
[2019-05-10T04:58:15.987Z] Outgoing network have been stubbed.
[2019-05-10T04:58:16.145Z] Checked functions.config()
[2019-05-10T04:58:16.376Z] firebase-admin has been stubbed.
âš Default "firebase-admin" instance created!
i functions: HTTP trigger initialized at http://localhost:9000/travel-wizard-995fa/us-central1/getUser
i functions: HTTP trigger initialized at http://localhost:9000/travel-wizard-995fa/us-central1/getTrip
[2019-05-10T04:58:39.964Z] [functions] GET request to function getUser accepted.
[2019-05-10T04:58:39.967Z] [functions] Waiting for runtime to be ready!
[2019-05-10T04:58:40.221Z] Functions runtime initialized.
i functions: Beginning execution of "getUser"
[2019-05-10T04:58:40.222Z] Disabled runtime features: undefined
[2019-05-10T04:58:40.596Z] Found google-gax at ../gFirebase/functions/node_modules/google-gax/build/src/index.js
[2019-05-10T04:58:40.596Z] Outgoing network have been stubbed.
[2019-05-10T04:58:40.723Z] Checked functions.config()
[2019-05-10T04:58:40.970Z] firebase-admin has been stubbed.
âš Default "firebase-admin" instance created!
[2019-05-10T04:58:41.028Z] Trigger "getUser" has been found, beginning invocation!
[2019-05-10T04:58:41.029Z]
[2019-05-10T04:58:41.029Z] Running getUser in mode HTTPS
[2019-05-10T04:58:41.035Z] {"socketPath":"/var/folders/9v/qyy4ytsj72150lcsmqnj3xc97fzvrl/T/firebase_emulator_invocation_32894.sock"}
[2019-05-10T04:58:41.035Z] [functions] Runtime ready! Sending request! {"socketPath":"/var/folders/9v/qyy4ytsj72150lcsmqnj3xc97fzvrl/T/firebase_emulator_invocation_32894.sock"}
[2019-05-10T04:58:41.041Z] Ephemeral server used!
Entered get User - User class
âš The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
âš Google API requested!
- URL: "https://oauth2.googleapis.com/token"
- Be careful, this may be a production service.
Error: 16 UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
[2019-05-10T04:58:50.219Z] Ephemeral server survived.
i functions: Finished "getUser" in ~9s
Thanks for this report, I'll take a look today and hopefully get a fix out with 6.9.2 in a few hours.
Looks like there's two issues here. Firstly, your main concern, that emulators:start will not allow you to access Firestore is actually the correct behavior, but we don't explain it well and could do with a better error message.
As of 6.9.1 we defined a split between serve and emulators:start functionality. When using serve, it's basically like running your functions normally, except the code is executed locally, so your functions will have access to production resources (like Firestore). When using emulators:start we do everything we can to keep you from hitting production resources and route requests back into the other emulators (like Cloud Firestore) and given a choice between hitting a production resource accidentally or throwing an error, we throw an error. This definitely needs to be explained better, but for right now my main concern is restoring the behavior of serve, which feels like the actual bug here.
It looks like you went to emulators:start because you're expecting serve --only functions --port 9000 to route the functions emulator to port 9000 and we broke that, so that (along with better messaging / docs for emulators:start) is what we'll fix.
I can take this one. I did not realize that --port could control non-Hosting servers if you used --only in the old implementation.
Fixed via #1267 and will be included in the next release (likely 6.9.2 will be the version number)
Version 6.9.2 has been released with this fix.
Thank you.. Works perfectly. :)
As a quick note, the link in this error is dead (404):
The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
âš Google API requested!
- URL: "oauth2.googleapis.com/token"
- Be careful, this may be a production service.
> Error: 16 UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See developers.google.com/identity/sign-in/web/devconsole-project.
Can we do something about the docs? I'm not really following what's going on.
I've spent the last couple of hours wondering why a function that I'm testing doesn't write to firestore.
Now it seems pretty obvious, but yea. I was on firebase-tools 6.11 and instead of a warning that I'm not writing to the real instance I got a type error related to grpc and a call to isSecure or something.
Now I updated to 7.0 and got this instead:
(node:19416) UnhandledPromiseRejectionWarning: TypeError: this.channel.credentials._getCallCredentials is not a function
> at CallCredentialsFilter.sendMetadata (./node_modules/@grpc/grpc-js/build/src/call-credentials-filter.js:40:61)
> at FilterStack.sendMetadata (./node_modules/@grpc/grpc-js/build/src/filter-stack.js:26:38)
> at Http2Channel._startHttp2Stream (./node_modules/@grpc/grpc-js/build/src/channel.js:188:50)
> at Http2CallStream.sendMetadata (./node_modules/@grpc/grpc-js/build/src/call-stream.js:338:22)
> at ServiceClientImpl.makeUnaryRequest (./node_modules/@grpc/grpc-js/build/src/client.js:136:14)
> at ServiceClientImpl.<anonymous> (./node_modules/@grpc/grpc-js/build/src/make-client.js:92:19)
> at ./node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:147:41
> at ./node_modules/google-gax/build/src/normalCalls/timeout.js:58:16
> at OngoingCall.call (./node_modules/google-gax/build/src/call.js:82:27)
> at NormalApiCaller.call (./node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:18:19)
> at funcPromise.then.then.apiCall (./node_modules/google-gax/build/src/createApiCall.js:84:30)
> (node:19416) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
> (node:19416) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> { Error: Getting metadata from plugin failed with error: this.credentials._getConnectionOptions is not a function
> at Http2CallStream.call.on (./node_modules/@grpc/grpc-js/build/src/client.js:102:45)
> at Http2CallStream.emit (events.js:202:15)
> at Http2CallStream.endCall (./node_modules/@grpc/grpc-js/build/src/call-stream.js:74:18)
> at ./node_modules/@grpc/grpc-js/build/src/call-stream.js:355:18
> code: 2,
> details:
> 'Getting metadata from plugin failed with error: this.credentials._getConnectionOptions is not a function',
> metadata: Metadata { internalRepr: Map {} } }
all I'm doing is a pretty basic admin.firestore().collection('').set() call.
When I run
firebase serve --only functions then everything works fine and I'm able to write firestore.
When we run the emulator with the --only function option what are we supposed to do with this message:
The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
âš Google API requested!
- URL: "oauth2.googleapis.com/token"
- Be careful, this may be a production service.
> Error: 16 UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See developers.google.com/identity/sign-in/web/devconsole-project.
@compojoom really sorry about this mess! Your credentials issue will be solved once this PR is included in a release:
https://github.com/firebase/firebase-tools/pull/1410
@samtstern - ah okaaaay! I always wonder why do I find those things right before you guys release a fix for them. Can't I find them after the fix is being released? :D:D:D
@compojoom version 7.0.1 includes the fix here. However the next version will also include compatibility with firebase-functions version 3.x. Right now that's broken and a known issue.
awesome! thanks! We are still on v2 of the functions, so all good for now.
I'm still encountering this same issue when calling gcs from functions.
// Terminal command: firebase serve --only functions --port=5001
// Package.json dependency: "firebase-functions": "^3.3.0"
exports.test = functions.https.onCall(async (data, context) =>{
var bucket = admin.storage().bucket()
bucket.getFiles().then((files)=>{
files.forEach(file => {
console.log(file.name);
});
}).catch((error)=>{
console.error(error);
});
return { test: "test" }
})
When calling the function i get the following error:
Google API requested!
- URL: "https://oauth2.googleapis.com/token"
- Be careful, this may be a production service.
> { GaxiosError: invalid_grant
> at Gaxios._request (/Users/snunez/Documents/Barhop/Barhop-functions/functions/node_modules/gaxios/build/src/gaxios.js:86:23)
> at processTicksAndRejections (internal/process/task_queues.js:86:5)
> response:
> { config:
> { method: 'POST',
> url: 'https://oauth2.googleapis.com/token',
> data:
> 'refresh_token=1%2F7Lms1FE5E5hIqwyx2uWSj8o4oNhky30_xh4K8fVh1edzJOFPPWCpNHUQxciWI3Ui&client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&client_secret=j9iVZfS8kkCEFUPaAeJV0sAi&grant_type=refresh_token',
> headers: [Object],
> params: [Object: null prototype] {},
> paramsSerializer: [Function: paramsSerializer],
> body:
> 'refresh_token=1%2F7Lms1FE5E5hIqwyx2uWSj8o4oNhky30_xh4K8fVh1edzJOFPPWCpNHUQxciWI3Ui&client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&client_secret=j9iVZfS8kkCEFUPaAeJV0sAi&grant_type=refresh_token',
> validateStatus: [Function: validateStatus],
> responseType: 'json' },
> data: { error: 'invalid_grant', error_description: 'Bad Request' },
> headers:
> { 'alt-svc':
> 'h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
> 'cache-control': 'private',
> connection: 'close',
> 'content-encoding': 'gzip',
> 'content-type': 'application/json; charset=utf-8',
> date: 'Thu, 30 Jul 2020 16:13:50 GMT',
> server: 'scaffolding on HTTPServer2',
> 'transfer-encoding': 'chunked',
> vary: 'Origin, X-Origin, Referer',
> 'x-content-type-options': 'nosniff',
> 'x-frame-options': 'SAMEORIGIN',
> 'x-xss-protection': '0' },
> status: 400,
> statusText: 'Bad Request',
> request: { responseURL: 'https://oauth2.googleapis.com/token' } },
> config:
> { method: 'POST',
> url: 'https://oauth2.googleapis.com/token',
> data:
> 'refresh_token=1%2F7Lms1FE5E5hIqwyx2uWSj8o4oNhky30_xh4K8fVh1edzJOFPPWCpNHUQxciWI3Ui&client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&client_secret=j9iVZfS8kkCEFUPaAeJV0sAi&grant_type=refresh_token',
> headers:
> { 'Content-Type': 'application/x-www-form-urlencoded',
> 'User-Agent': 'google-api-nodejs-client/6.0.5',
> 'x-goog-api-client': 'gl-node/11.14.0 auth/6.0.5',
> Accept: 'application/json' },
> params: [Object: null prototype] {},
> paramsSerializer: [Function: paramsSerializer],
> body:
> 'refresh_token=1%2F7Lms1FE5E5hIqwyx2uWSj8o4oNhky30_xh4K8fVh1edzJOFPPWCpNHUQxciWI3Ui&client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&client_secret=j9iVZfS8kkCEFUPaAeJV0sAi&grant_type=refresh_token',
> validateStatus: [Function: validateStatus],
> responseType: 'json' },
> code: '400' }
GaxiosError: invalid_grant^CShutting down...
I have tried reAuthenticating using 'firebase logout/login' but no luck