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.
@imarian97 Can you run
cd ~/.config/gcloud
ls
if there's a file called application_default_credentials.json, remove it by running:
rm application_default_credentials.json
I'm on Windows but I've found the file in %appdata%/gcloud and now, after I removed the file, it works.
Thanks!
Great! Thanks for the update.
Forgive me for asking, but what did this actually do? It worked for me as well. I think I upgraded firebase_tools at some point, and I've also been switching between dev & prod environments a bit.
It looks like application_default_credentials.json is recreated when I restart the local server?
@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.
Thanks for the response Lauren.
I got this error when running the shell, but was resolved by deleting the file.
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.
same here. First time I encounter error today, so not local, but on google deployed server.
I sent bug report to google
@kylehotchkiss @raDiesle getting the same thing here, cloud functions no longer work
Auth error:Error: Could not refresh access token.
| awa | Error: 16 UNAUTHENTICATED: Getting metadata from plugin failed with error: Could not refresh access token. at createStatusError (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:65:15) at ClientReadableStream._emitStatusIfDone (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:271:19) at ClientReadableStream._receiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:249:8) at /user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:715:12 |
|---|
@raDiesle @sionfletcher i mailed firebase's technical support, hopefully that will get their attention
@laurenzlong Hi Lauren, Any chance you could flag this on Google's end?
Additionally, SO users filing: https://stackoverflow.com/questions/48550151/after-deploy-cloud-functions-error-could-not-refresh-access-token
@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?
Might be good to add those to Firebase's bug form: https://firebase.google.com/support/contact/bugs-features/
I sent quick Firebase bug form with category: cloud functions
I've had a support request in for a couple hours and no reply yet or official word in Slack yet.
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."
Issue is now being tracked on the status page https://status.firebase.google.com/incident/Functions/18011
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:
- Either wait for the npm caches to pick up the new version, or explicitly request google-gax 0.14.5 in your package.json.
- Re-deploy your functions.
That should resolve things. If you're still having trouble, please let us know!
Thanks, @rjhuijsman, works for me