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

Unhelpful error message when credentials misssing #620

Closed
ofrobots opened this issue Feb 7, 2019 · 8 comments · Fixed by googleapis/nodejs-common#480
Closed

Unhelpful error message when credentials misssing #620

ofrobots opened this issue Feb 7, 2019 · 8 comments · Fixed by googleapis/nodejs-common#480
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@ofrobots
Copy link
Contributor

ofrobots commented Feb 7, 2019

I was trying to use a Node.js client library (any, doesn't matter) in a Node.js express server. I started the app without providing credentials. I expected an error, but the error I got was less than useful.

Error: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

Problems:

  1. I can follow the link by ⌘-clicking in the terminal. It would be good if there wasn't a trailing dot which leads to a 404.
  2. The error page talks about 'Google Sign-In' and 'WebApp'. This was a Node.js server, not a WebApp, and I am not trying to use Google Sign In. The error page seems wrong. I expected to be taken to a page that talks about Service Accounts and OAuth2.
@JustinBeckwith JustinBeckwith self-assigned this Feb 7, 2019
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Feb 8, 2019
@JustinBeckwith JustinBeckwith added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Feb 9, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Feb 9, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Feb 19, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Mar 4, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Mar 14, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Mar 21, 2019
@JustinBeckwith
Copy link
Contributor

👋 so I'm finally getting to look at this one. When I try it, I am getting this:

node listQueues.js 
/Users/beckwith/Code/nodejs-tasks/samples/node_modules/@google-cloud/tasks/src/v2/cloud_tasks_client.js:178
              throw err;
              ^

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
    at GoogleAuth.<anonymous> (/Users/beckwith/Code/nodejs-tasks/samples/node_modules/google-auth-library/build/src/auth/googleauth.js:168:23)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/beckwith/Code/nodejs-tasks/samples/node_modules/google-auth-library/build/src/auth/googleauth.js:19:58)
    at processTicksAndRejections (internal/process/task_queues.js:86:5)

I found that doc to be much more helpful :) Can you share the steps you're using to get that error? It's entirely possible this is something we accidentally fixed.

@JustinBeckwith JustinBeckwith added priority: p2 Moderately-important priority. Fix may not be included in next release. needs more info This issue needs more information from the customer to proceed. and removed priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Mar 29, 2019
@yoshi-automation yoshi-automation removed the 🚨 This issue needs some love. label Mar 29, 2019
@ofrobots
Copy link
Contributor Author

I don't remember the precise steps. I tried reproducing from scratch in the way I expect I would have done originally:

(node:73218) UnhandledPromiseRejectionWarning: Error: Sorry, we cannot connect to Cloud Services without a project
 ID. You may specify one with an environment variable named
 "GOOGLE_CLOUD_PROJECT".
    at replaceProjectIdToken (/Users/ofrobots/tmp/bunyan-test/node_modules/@google-cloud/projectify/build/src/index.js:45:19)
    at Object.replaceProjectIdToken (/Users/ofrobots/tmp/bunyan-test/node_modules/@google-cloud/projectify/build/src/index.js:38:30)
    at self.auth.getProjectId (/Users/ofrobots/tmp/bunyan-test/node_modules/@google-cloud/logging/build/src/index.js:719:40)
    at getProjectIdAsync.then.r (/Users/ofrobots/tmp/bunyan-test/node_modules/google-auth-library/build/src/auth/googleauth.js:73:48)
    at process.internalTickCallback (internal/process/next_tick.js:77:7)

This seems different / more reasonable.

Let me see if I can reproduce some other way.

@ofrobots
Copy link
Contributor Author

Here's a repro, in a new dir, add @google-cloud/debug-agent a dependency and the following code:

require('@google-cloud/debug-agent').start({
  allowExpressions: true,
  projectId: 'ofrobots-test-19'   // <-- change this to your own project
});

setTimeout(() => {}, 10000);

Run gcloud auth revoke, and then:

❯ node index.js
@google-cloud/debug-agent Failed to re-register debuggee ofrobots-test-19: Error: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
@google-cloud/debug-agent Failed to re-register debuggee ofrobots-test-19: Error: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
@google-cloud/debug-agent Failed to re-register debuggee ofrobots-test-19: Error: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

@ofrobots ofrobots removed the needs more info This issue needs more information from the customer to proceed. label Mar 29, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Aug 6, 2019
@JustinBeckwith
Copy link
Contributor

Ok - I finally tracked this one down. It's a bug on nodejs-common:
https://github.com/googleapis/nodejs-common/blob/master/src/util.ts#L607

Even if auth fails, it still decides "hell, maybe we won't need a token!" and sends the request to the backend anyway. The error message we're getting is part of the body from the 401 response that comes back from the debug API itself.

I can't imagine why we wouldn't fail in this scenario with the original call stack. Uh, @stephenplusplus ?

@stephenplusplus
Copy link
Contributor

Original PR: googleapis/google-cloud-node#2712

Failing with the original call stack would make sense to me, too.

@stephenplusplus
Copy link
Contributor

Just in case I misunderstood what you meant by fail, the first error message would be more helpful, but I believe we still need to attempt the API request, as they don't all require authentication.

It might not be so easy, though, to define the condition that we want to ignore the API failure message and use the auth lib's. Maybe only when it's a 401?

@JustinBeckwith
Copy link
Contributor

If the API endpoint requires credentials, and we can't acquire them - the original callstack would be very nice here. The 401 approach is fine.

I am curious though ... what's the use case for this one? I'm sure we had a good reason, it's just not called out in the PR.

@stephenplusplus
Copy link
Contributor

I believe Storage.File#download, but there might be others by now. My bad for not leaving a better trail in that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants