firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Getting metadata from plugin failed with error: invalid_grant

Open imarian97 opened this issue 9 years ago • 33 comments

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

  1. 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);
    });
});
  1. Enable firestore in firebase console with public acces security rules:
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}
  1. Serve
firebase serve --only functions
  1. 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 avatar Oct 16 '17 22:10 imarian97

@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

laurenzlong avatar Oct 16 '17 22:10 laurenzlong

I'm on Windows but I've found the file in %appdata%/gcloud and now, after I removed the file, it works.

Thanks!

imarian97 avatar Oct 16 '17 22:10 imarian97

Great! Thanks for the update.

laurenzlong avatar Oct 16 '17 23:10 laurenzlong

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 avatar Nov 25 '17 01:11 TheRoccoB

@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.

laurenzlong avatar Nov 27 '17 22:11 laurenzlong

Thanks for the response Lauren.

TheRoccoB avatar Nov 27 '17 23:11 TheRoccoB

I got this error when running the shell, but was resolved by deleting the file.

alexbjorlig avatar Jan 12 '18 08:01 alexbjorlig

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.

kylehotchkiss avatar Jan 31 '18 19:01 kylehotchkiss

same here. First time I encounter error today, so not local, but on google deployed server.

I sent bug report to google

raDiesle avatar Jan 31 '18 19:01 raDiesle

@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

sionfletcher avatar Jan 31 '18 19:01 sionfletcher

@raDiesle @sionfletcher i mailed firebase's technical support, hopefully that will get their attention

kylehotchkiss avatar Jan 31 '18 19:01 kylehotchkiss

@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 avatar Jan 31 '18 19:01 kylehotchkiss

@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?

Mph1399 avatar Jan 31 '18 20:01 Mph1399

Might be good to add those to Firebase's bug form: https://firebase.google.com/support/contact/bugs-features/

kylehotchkiss avatar Jan 31 '18 20:01 kylehotchkiss

I sent quick Firebase bug form with category: cloud functions

raDiesle avatar Jan 31 '18 20:01 raDiesle

I've had a support request in for a couple hours and no reply yet or official word in Slack yet.

moneal avatar Jan 31 '18 21:01 moneal

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."

Mph1399 avatar Jan 31 '18 21:01 Mph1399

Issue is now being tracked on the status page https://status.firebase.google.com/incident/Functions/18011

moneal avatar Jan 31 '18 22:01 moneal

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!

rjhuijsman avatar Feb 01 '18 02:02 rjhuijsman

Thanks, @rjhuijsman, works for me

sionfletcher avatar Feb 01 '18 08:02 sionfletcher