Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting metadata from plugin failed with error: invalid_grant #121

Closed
imarian97 opened this issue Oct 16, 2017 · 25 comments

Comments

Projects
None yet
@imarian97
Copy link

commented Oct 16, 2017

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.

@laurenzlong

This comment has been minimized.

Copy link
Member

commented Oct 16, 2017

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

This comment has been minimized.

Copy link
Author

commented Oct 16, 2017

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

Thanks!

@laurenzlong

This comment has been minimized.

Copy link
Member

commented Oct 16, 2017

Great! Thanks for the update.

@TheRoccoB

This comment has been minimized.

Copy link

commented Nov 25, 2017

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?

@laurenzlong

This comment has been minimized.

Copy link
Member

commented Nov 27, 2017

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

@TheRoccoB

This comment has been minimized.

Copy link

commented Nov 27, 2017

Thanks for the response Lauren.

@dauledk

This comment has been minimized.

Copy link

commented Jan 12, 2018

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

@kylehotchkiss

This comment has been minimized.

Copy link

commented Jan 31, 2018

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.

@raDiesle

This comment has been minimized.

Copy link

commented Jan 31, 2018

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

I sent bug report to google

@sionfletcher

This comment has been minimized.

Copy link

commented Jan 31, 2018

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

@kylehotchkiss

This comment has been minimized.

Copy link

commented Jan 31, 2018

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

@kylehotchkiss

This comment has been minimized.

Copy link

commented Jan 31, 2018

@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

@Mph1399

This comment has been minimized.

Copy link

commented Jan 31, 2018

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

@kylehotchkiss

This comment has been minimized.

Copy link

commented Jan 31, 2018

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

@raDiesle

This comment has been minimized.

Copy link

commented Jan 31, 2018

I sent quick Firebase bug form with category: cloud functions

@moneal

This comment has been minimized.

Copy link

commented Jan 31, 2018

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

@Mph1399

This comment has been minimized.

Copy link

commented Jan 31, 2018

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

@moneal

This comment has been minimized.

Copy link

commented Jan 31, 2018

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

@rjhuijsman

This comment has been minimized.

Copy link
Contributor

commented Feb 1, 2018

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!

@sionfletcher

This comment has been minimized.

Copy link

commented Feb 1, 2018

Thanks, @rjhuijsman, works for me

@FrozenPandaz

This comment has been minimized.

Copy link

commented Feb 1, 2018

I still seem to be having issues, i have installed google-gax@0.14.5 but i still get that error when running firebase serve

@pcnate

This comment has been minimized.

Copy link

commented Feb 1, 2018

I randomly find the same issue on Ubuntu@17.10 with firebase@3.17.3
Removing the ~/.config/gloud/application_default_credentials.json temporarily resolves the issue

@m0ngr31

This comment has been minimized.

Copy link

commented Feb 1, 2018

Seems to solve the issue @rjhuijsman. Thanks.

@jpagex

This comment has been minimized.

Copy link

commented Mar 14, 2018

I am still having the issue.
I tried several things:

  • Installing google-gax@0.14.5
  • Removing functions, disabling Cloud Functions API and redeploying the functions

It keeps failing.

Any solution?

@laurenzlong

This comment has been minimized.

Copy link
Member

commented Mar 14, 2018

@jpagex It's hard to diagnose without more information.

  1. If you are seeing this when EMULATED functions: update firebase-tools to latest, then try again. This was a resolved bug. If that doesn't work, then file an issue on https://github.com/firebase/firebase-tools
  2. If you are seeing this in DEPLOYED functions, file a support ticket at firebase.google.com/support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.