Google-cloud-node: Error: Missing key, key or keyFile option must be provided!

Created on 17 Oct 2014  路  21Comments  路  Source: googleapis/google-cloud-node

While using gcloud on my own local server, I write:

var gcloud = require('gcloud');
var bucket;

bucket = gcloud.storage.bucket({
    projectId: 'myProjectName',
    keyFilename: 'resources/key.json',
    bucketName: 'testnameorwhatever'
});

bucket.write('demo.txt', 'Hello World', function(err) {
        var stuff = err || 'Created demo.txt'
        console.log(stuff);
});

if I do specify the right path to the key, it gives this output (not thrown error, just console log):
[Error: Missing key, key or keyFile option must be provided!]
I do not understand this message. There is a key specified, and the path to it is right. I know that, as if I write the wrong keyFilename path, it throws _ENOENT error 34_. So, is it about the key description or something?

bug storage triage me

Most helpful comment

I'd say this issue comes down to a misunderstanding of the error message. The error itself is suggesting that a keyFile or key parameter should be specified, when really the error should suggest that they are likely using an invalid key file. Should we improve this err message?

All 21 comments

Which version of gcloud-node are you using?

the latest one, I guess. 0.8.1

Can you verify that in yourproject/node_modules/gcloud-node/package.json? :)

Yeah, here is a fraction of it:

{
  "name": "gcloud",
  "version": "0.8.1",
  "author": {
    "name": "Google Inc."
  },
  "description": "Google Cloud APIs Client Library for Node.js",
...

Thanks, I'll play around and try to find the :bug:

Just in case I am dumb and use the wrong key, my key json has these fields in it:

{"web":{"auth_uri":"https://accounts.google.com/o/oauth2/auth", "client_secret": ..., "token_uri":...

and so on. Is that the right key? :)

Not dumb at all! There are a million things you can do in the Developers Console, it's very easy to get lost.

I believe you are using a client ID for a webapp, where what we want is a service account. https://github.com/GoogleCloudPlatform/gcloud-node/#elsewhere step 4 should show how to do that.

I'm going to close as I was able to reproduce the same error with a webapp key, and remedy it with a service key. If you run into anything else, ask away!

I'd say this issue comes down to a misunderstanding of the error message. The error itself is suggesting that a keyFile or key parameter should be specified, when really the error should suggest that they are likely using an invalid key file. Should we improve this err message?

Seems the error is created in gapitoken so we have no control over the error message, unless we do some of our own sanity checking when passing in the key / key file.

I'm try to use the same feature and I've the same error.

Have a fix to this problem?

Nothing... I try to pass the client_email and the private_key manual, but I recive this error:

12176:error:0906D06C:PEM routines:PEM_read_bio:no start line:openssl\crypto\pem\pem_lib.c:703:Expecting: ANY PRIVATE KEY

You generated a service account JSON key from the developer's console, and it looked like:

{
  "private_key_id": "...",
  "private_key": "...",
  "client_email": "[email protected]",
  "client_id": "....apps.googleusercontent.com",
  "type": "service_account"
}

You instantiated gcloud like:

require('gcloud')({
  credentials: {
    private_key: '...',
    client_email: '[email protected]'
  }
});

and got that error?

More code that shows what you're doing and full stack traces would help me debug.

My JSON not is in this format.

The private_key have only ~16 chars. I'm almost on madness to solve this problem. :(

How did you get the key? And as mentioned before, code snippets of what's causing the error and a stack trace would help us alleviate the madness :)

I'm not proprietary of the project on the Google Cloud.

This is my view to get the json or the client and private keys.
http://imgur.com/i4ZFKT4

var gcloud = require('gcloud');
var storage = gcloud.storage({
  projectId: 'teste-edco',
  keyFilename: __dirname +'/client.json'
  /*credentials: {
    client_email: 'email',
    private_key: '26chars_key'
  }*/
});

When I try to use only the credentials I get the error:

21188:error:0906D06C:PEM routines:PEM_read_bio:no start line:openssl\crypto\pem\pem_lib.c:703:Expecting: ANY PRIVATE KEY

crypto.js:398
  var ret = this._binding.sign(toBuf(key));
                          ^
Error: SignFinal error
    at Sign.sign (crypto.js:398:27)
    at createRS256Signature (C:\PROG\Work\POCs\ebclient2-plugin-client-cc-youtube\testes\node_modules\gcloud\node_modules\gapitoken\node_modules\jws\index.js:75:58)
    at jwsRS256Sign (C:\PROG\Work\POCs\ebclient2-plugin-client-cc-youtube\testes\node_modules\gcloud\node_modules\gapitoken\node_modules\jws\index.js:68:21)
    at Object.jwsSign [as sign] (C:\PROG\Work\POCs\ebclient2-plugin-client-cc-youtube\testes\node_modules\gcloud\node_modules\gapitoken\node_modules\jws\index.js:32:12)
    at GAPI.getAccessToken (C:\PROG\Work\POCs\ebclient2-plugin-client-cc-youtube\testes\node_modules\gcloud\node_modules\gapitoken\gapitoken.js:57:25)
    at GAPI.getToken (C:\PROG\Work\POCs\ebclient2-plugin-client-cc-youtube\testes\node_modules\gcloud\node_modules\gapitoken\gapitoken.js:36:14)
    at C:\PROG\Work\POCs\ebclient2-plugin-client-cc-youtube\testes\node_modules\gcloud\lib\common\connection.js:211:10
    at process._tickCallback (node.js:419:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)

From the screenshot, it looks like you have a Client ID for native apps and an API Key for a server app. What you need is a Client ID for a Service Account, so you should ask the owner of your project to create one.

@silvolu, I try these for one project I'm owner, but yet I have the same problems

When you use the project you own, are you using a Client ID for service accounts? In other words, if you navigate to the Google Developers Console, choose the project and navigate to the Credentials tab, does it say Service Account (_conta de servi莽o_ according to Google Translate) over the Client ID that you're using?

THANKS VERY MUCH!

Thanks again, and again for the patience. Now I can go to the next step :ghost:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

charly37 picture charly37  路  3Comments

mik115 picture mik115  路  5Comments

pputhran picture pputhran  路  4Comments

VikramTiwari picture VikramTiwari  路  3Comments

sporkd picture sporkd  路  5Comments