googleapis / nodejs-storage

Node.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
https://cloud.google.com/storage/
Apache License 2.0
900 stars 369 forks source link

Error: Could not refresh access token. #443

Closed ils-sapnaj closed 6 years ago

ils-sapnaj commented 6 years ago

I am getting this error " Error: Could not refresh access token" when uploading an image to google bucket.

OS: Windows 10 Node.js version: 8.11.4 npm version: 5.6.0 @google-cloud/storage version: 2.0.3

Below is the code :

"dependencies": { "@google-cloud/storage": "^2.0.3", "adm-zip": "0.4.7", "apn": "^1.7.8", "assert-plus": "0.2.0", "async": "0.2.9", "asynckit": "0.4.0", "aws-sdk": "2.122.0", "aws-sign2": "0.6.0", "aws4": "1.6.0", "babel-core": "", "babel-istanbul": "", "base-64": "^0.1.0", "base64url": "2.0.0", "bluebird": "^3.5.1", "body-parser": "~1.15.1", "chai": "^4.2.0", "connect-flash": "~0.1.1", "cookie-parser": "~1.4.3", "dateformat": "3.0.2", "debug": "~2.2.0", "ejs": "~2.5.7", "end-of-stream": "1.4.0", "express": "~4.13.4", "express-session": "~1.14.2", "extend": "3.0.0", "extract-zip": "^1.6.5", "extsprintf": "1.0.2", "fcm-node": "1.2.1", "fiber": "1.0.4", "fibers": "2.0.0", "forever-agent": "0.6.1", "form-data": "2.1.4", "gcloud": "^0.37.2", "gcp-metadata": "0.3.1", "group-array": "0.3.1", "http-signature": "1.1.1", "jenkins-mocha": "^4.1.2", "json-schema": "0.2.3", "json-stable-stringify": "1.0.1", "json-stringify-safe": "5.0.1", "log-driver": "1.2.5", "mailchimp-api-v3": "1.7.0", "make-dir": "1.1.0", "md5": "~2.2.1", "methmeth": "1.1.0", "mime": "1.4.1", "mime-db": "1.27.0", "mime-types": "2.1.15", "mocha": "1.14.0", "mocha-logger": "^1.0.5", "modelo": "4.2.0", "moment": "^2.20.1", "morgan": "~1.7.0", "multer": "1.3.0", "mysql": "~2.11.1", "newrelic": "^2.7.0", "node-datetime": "1.0.0", "node-forge": "0.6.49", "node-gyp": "^3.8.0", "node-pre-gyp": "^0.11.0", "node-stream-zip": "^1.3.7", "nodemailer": "^2.6.4", "npm": "^3.10.10", "nyc": "^11.2.1", "paypal-rest-sdk": "1.8.1", "readable-stream": "2.3.3", "request": "2.81.0", "retry-request": "3.1.0", "rimraf": "2.6.2", "rmdir-sync": "1.0.1", "safe-buffer": "5.0.1", "safe-json-stringify": "^1.0.4", "serve-favicon": "^2.3.2", "slashes": "~1.0.5", "sort-by": "1.2.0", "sql.js": "0.4.0", "stubs": "3.0.0", "typedarray": "0.0.6", "unique-string": "1.0.0", "util-deprecate": "1.0.2", "uuid": "3.0.1", "wait.for": "0.6.6" },

and it is a simple code of uploading file on google bucket :

    var fs = require("fs");
var mime = require('mime-types')
    var {Storage} = require('@google-cloud/storage');
var mimetyp = mime.lookup(image_look_up_path);

if (fs.existsSync(image_look_up_path))
{
    var storage = new Storage
    ({
      projectId: project_id,
      keyFilename: './GCP_credential.json'
    })

    var bucket = storage.bucket(CLOUD_BUCKET);
    var files = bucket.file(space+'/'+user_email+'/'+image_file_name);
    fs.createReadStream(image_look_up_path)
    .pipe(files.createWriteStream
    ({
        metadata:
        {
          contentType: mimetyp
        },
        predefinedAcl: "publicRead"
    }))
    .on("error", (err) =>
    {
        console.log("err : "+err);
    })
    .on('finish', () =>
    {
        console.log("Done");
    });
    return callback(null, "done");

I am able to get what is the issue - earlier it was giveing "could not authenticate request" which automatically gone and now it is giving " Could not refresh access token". Please tell me what to do as my development is stuck at this point.

jkwlui commented 6 years ago

Hi @ils-sapnaj, how are you authenticated with the Storage client (service account, etc)?

ils-sapnaj commented 6 years ago

Yes I am using service account.

On Sat, Nov 3, 2018, 3:09 AM Jonathan Lui <notifications@github.com wrote:

Hi @ils-sapnaj https://github.com/ils-sapnaj, how are you authenticated with the Storage client (service account, etc)?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/googleapis/nodejs-storage/issues/443#issuecomment-435517206, or mute the thread https://github.com/notifications/unsubscribe-auth/AeEeV5zK234NbBUq9ceiPZcH6TarEA1jks5urLuqgaJpZM4XXjY5 .

-- ----------*----------- This email and any attachments are confidential and intended only for the individual(s) named. If you are not the named addressee or have received this email by mistake, please (a) notify the sender, and (b) delete this email immediately without distributing or retaining. The sender does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.

Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the organization. Our employees, contractors & students are expressly required not to infringe on copyright or any other law. Any such communication is contrary to company policy and outside the scope of his/her engagement with the company,will not accept any liability in respect of such communication, and he/she will be personally responsible and liable for any damages.

jkwlui commented 6 years ago

Can you verify that your service account has the correct roles? If possible, can you create a new service account and use the new key and see if the situation changes. https://cloud.google.com/docs/authentication/getting-started

I've tried to use the provided code and was able to successfully upload a file.

stephenplusplus commented 6 years ago

@ils-sapnaj I'm going to close the issue, since we cannot reproduce. If you tried @kinwa91's previous suggestion, and are still facing issues, let me know and we'll re-open until we solve it!