firebase-functions: Getting metadata from plugin failed with error: invalid_grant
Version info
firebase-functions: 0.7.1
firebase-tools: 3.13.1
firebase-admin: 5.4.2
Test case
Trying to get a firestore doc in HTTP cloud functions returns this error in the local emulator (firebase serve --only functions
)
error: Auth error:Error: invalid_grant
error: { Error: Getting metadata from plugin failed with error: invalid_grant
at ClientReadableStream._emitStatusIfDone (C:\Users\imari\Desktop\PROJECTS\dance-reg\functions\node_modules\firebase-admin\node_modules\grpc\src\node\src\client.js:255:19)
at ClientReadableStream._receiveStatus (C:\Users\imari\Desktop\PROJECTS\dance-reg\functions\node_modules\firebase-admin\node_modules\grpc\src\node\src\client.js:233:8)
at C:\Users\imari\Desktop\PROJECTS\dance-reg\functions\node_modules\firebase-admin\node_modules\grpc\src\node\src\client.js:705:12 code: 16, metadata: Metadata { _internal_repr: {} } }
Steps to reproduce
- Init a new firebase functions project with this index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var db = admin.firestore();
exports.myFunc= functions.https.onRequest((req, res) => {
return db.doc("athletes/1").get().then(doc=>{
if(doc.exists){
console.log(doc.data());
res.send(doc.data())
}
}).catch(err=>{
console.error(err);
});
});
- Enable firestore in firebase console with public acces security rules:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
- Serve
firebase serve --only functions
- Test
curl -X GET "http://localhost:5000/my-test-project/us-central1/myFunc"
Were you able to successfully deploy your functions?
Yes, the deploy is successful. The issue appears only locally.
Expected behavior
The expected behavior is to log the firestore document in the console and send it as an HTTP response.
Actual behavior
The get()
promise is rejected with the above mentioned error.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 33 (5 by maintainers)
@imarian97 Can you run
if there’s a file called
application_default_credentials.json
, remove it by running:I had the same problem.I tried several things:
but It didn´t work. the way to solved it for me was installing cloud sdk and after that execute
gcloud auth application-default login
to generate again the ADC.I just got a Firebase ticket response saying: "Hi there,
Thanks for reaching out. We’re currently investigating the issue with refreshing Authentication token. We’ll get back to you as soon as we have more information to share."
I’m on Windows but I’ve found the file in
%appdata%/gcloud
and now, after I removed the file, it works.Thanks!
@kylehotchkiss @raDiesle getting the same thing here, cloud functions no longer work
Auth error:Error: Could not refresh access token.
@raDiesle @sionfletcher i mailed firebase’s technical support, hopefully that will get their attention
Issue is now being tracked on the status page https://status.firebase.google.com/incident/Functions/18011
@TheRoccoB Yes it does get recreated when you run the local server. If the file already exists, then the Firebase CLI will not create one. Since an existing file (created by gcloud CLI or an older firebase CLI) may not have adequate access levels, you may encounter issues when trying to access certain features. Deleting it manually allows Firebase CLI to re-create the file with credentials that have the access levels you need. We are working to change the way credentials work in the local emulator so problems like this won’t occur.
I just forgot executing below after rebooting mac…
(c.f. https://firebase.google.com/docs/admin/setup#initialize_the_sdk)
Thanks everyone for the reports, both here and especially also via our tech support channels - these really help.
We believe the issue to have been caused by a problem deep in our Node.js dependency chain, in particular for users of Firestore. We’ve just released https://www.npmjs.com/package/google-gax 0.14.5 to address the issue. Please:
That should resolve things. If you’re still having trouble, please let us know!
@kylehotchkiss -I’m getting the same issue after a deploy today. The same code was working last night. I don’t have an application_default_credentials.json file to remove as suggested above so I’m not sure what else to do but maybe wait for a fix from Firebase?
I’m encountering this error on Firebase Functions on Google’s side. I can’t figure it out 😭. I tried deleting and repushing function but no luck.