google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Code breaking while authenticating

Open VikramTiwari opened this issue 11 years ago • 4 comments

I am connecting to big query using JWT client. My application is high scale and makes this connection every time it wants to stream data into big query.

Any possible fix to this?

Raw error log;

crypto.js:398
  var ret = this._binding.sign(toBuf(key));
                          ^
TypeError: Not a buffer
    at Sign.sign (crypto.js:398:27)
    at createRS256Signature (/home/ubuntu/vikram/test/shock/node_modules/googleapis/node_modules/gapitoken/node_modules/jws/index.js:75:58)
    at jwsRS256Sign (/home/ubuntu/vikram/test/shock/node_modules/googleapis/node_modules/gapitoken/node_modules/jws/index.js:68:21)
    at Object.jwsSign [as sign] (/home/ubuntu/vikram/test/shock/node_modules/googleapis/node_modules/gapitoken/node_modules/jws/index.js:32:12)
    at GAPI.getAccessToken (/home/ubuntu/vikram/test/shock/node_modules/googleapis/node_modules/gapitoken/gapitoken.js:56:25)
    at GAPI.getToken (/home/ubuntu/vikram/test/shock/node_modules/googleapis/node_modules/gapitoken/gapitoken.js:35:14)
    at JWT.refreshToken_ (/home/ubuntu/vikram/test/shock/node_modules/googleapis/lib/auth/jwtclient.js:89:13)
    at /home/ubuntu/vikram/test/shock/node_modules/googleapis/lib/auth/jwtclient.js:68:12
    at /home/ubuntu/vikram/test/shock/node_modules/googleapis/node_modules/gapitoken/gapitoken.js:20:17
    at fs.js:266:14

VikramTiwari avatar Feb 20 '15 09:02 VikramTiwari

This doesn't really help me diagnose the issue. Can you post a code snippet I could use to reproduce the error?

ryanseys avatar Feb 20 '15 17:02 ryanseys

I can't provide any code snippet, but the procedure is as follows:

Stream the data from a source (filesystem or API) Process that data into fields for Big Query Authenticate using JWT Stream the data to big query to save

Does this makes sense? If not i will write a sample code to replicate the error.

VikramTiwari avatar Feb 23 '15 09:02 VikramTiwari

 function InstertStreamInBQ(dataObj, tableName, callback){
     // get authentication
    jwtClient.authorize(function(err, tokens) {
        if (err) {
            console.log(err);
            return;
        }

        // request body for big query
        var request_body = {
            "kind": "bigquery#tableDataInsertAllRequest",
            "rows": [{
                "insertId": dataObj.uuid,
                "json": dataObj
            }]
        }

        // save the data in big query's table
        bq.tabledata.insertAll({
            auth: jwtClient,
            datasetId: config.datasetId,
            projectId: config.projectId,
            tableId: tableName,
            resource: request_body
        }, function(err, resp) {
            if(err){
                callback(err, null);
                console.log("Error in bigquery stream save data @ bigquery.js : tableName ", err)
            }else{
                 callback(null, resp);
        });
      }

This is the sample code I am using to stream data in bigquery and getting the same error during the load as described by @VikramTiwari. Could you pls suggest a way to overcome it.

vivekkrbajpai avatar Mar 25 '15 09:03 vivekkrbajpai

Greetings folks! We've made a lot of changes to the auth library over the last few months, and there's a good chance this is fixed. If you're still running into problems, please feel free to open another issue!

JustinBeckwith avatar Feb 22 '18 06:02 JustinBeckwith