From 7798bceb7f6e5d873f2f1607a9a4e922b38ced12 Mon Sep 17 00:00:00 2001 From: afirstenberg Date: Sat, 26 Oct 2013 01:24:24 -0400 Subject: [PATCH 1/3] Fix multipart bodies vanishing When re-authing during a multipart, the bodies of the multipart appear to be empty. This keeps a copy of the body and reconstitutes the body on the second call. --- lib/auth/oauth2client.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/auth/oauth2client.js b/lib/auth/oauth2client.js index 4566fdb168b..0766111c49b 100644 --- a/lib/auth/oauth2client.js +++ b/lib/auth/oauth2client.js @@ -176,6 +176,7 @@ OAuth2Client.prototype.revokeToken = function(token, opt_callback) { */ OAuth2Client.prototype.request = function(opts, opt_callback, opt_dontForceRefresh) { + console.log( 'oauth2client.request', opts, opt_dontForceRefresh ); var that = this; var credentials = this.credentials; @@ -188,6 +189,14 @@ OAuth2Client.prototype.request = opts.headers = opts.headers || {}; opts.headers['Authorization'] = credentials.token_type + ' ' + credentials.access_token; + + // Make a reference copy of the multipart bodies + var bodies = []; + if( opts.multipart ){ + opts.multipart.forEach(function(part){ + bodies.push( part.body ); + }); + } this.transporter.request(opts, function(err, body, res) { // TODO: Check if it's not userRateLimitExceeded @@ -203,6 +212,12 @@ OAuth2Client.prototype.request = var tokens = result; tokens.refresh_token = credentials.refresh_token; that.credentials = tokens; + + // Refresh the bodies + bodies.forEach( function(body,i){ + opts.multipart[i].body = body; + }); + that.request(opts, opt_callback, true); } }); From 466101c110f8304dc215b71fc7a818122fc4a8c1 Mon Sep 17 00:00:00 2001 From: afirstenberg Date: Sat, 26 Oct 2013 01:28:54 -0400 Subject: [PATCH 2/3] remove debugging --- lib/auth/oauth2client.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/auth/oauth2client.js b/lib/auth/oauth2client.js index 0766111c49b..e350136895a 100644 --- a/lib/auth/oauth2client.js +++ b/lib/auth/oauth2client.js @@ -176,7 +176,6 @@ OAuth2Client.prototype.revokeToken = function(token, opt_callback) { */ OAuth2Client.prototype.request = function(opts, opt_callback, opt_dontForceRefresh) { - console.log( 'oauth2client.request', opts, opt_dontForceRefresh ); var that = this; var credentials = this.credentials; From 5100c51b7b6ef92f637085d239202ca22bc53bec Mon Sep 17 00:00:00 2001 From: afirstenberg Date: Tue, 5 Nov 2013 13:08:57 -0500 Subject: [PATCH 3/3] Cleanup by gjslint/fixjsstyle --- lib/auth/oauth2client.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/auth/oauth2client.js b/lib/auth/oauth2client.js index e350136895a..7f54d20292e 100644 --- a/lib/auth/oauth2client.js +++ b/lib/auth/oauth2client.js @@ -135,7 +135,7 @@ OAuth2Client.prototype.refreshAccessToken = function(callback) { var that = this; - if (! this.credentials.refresh_token){ + if (! this.credentials.refresh_token) { throw new Error('No refresh token is set'); } @@ -188,12 +188,12 @@ OAuth2Client.prototype.request = opts.headers = opts.headers || {}; opts.headers['Authorization'] = credentials.token_type + ' ' + credentials.access_token; - + // Make a reference copy of the multipart bodies var bodies = []; - if( opts.multipart ){ - opts.multipart.forEach(function(part){ - bodies.push( part.body ); + if (opts.multipart) { + opts.multipart.forEach(function(part) { + bodies.push(part.body); }); } @@ -211,12 +211,12 @@ OAuth2Client.prototype.request = var tokens = result; tokens.refresh_token = credentials.refresh_token; that.credentials = tokens; - + // Refresh the bodies - bodies.forEach( function(body,i){ + bodies.forEach(function(body, i) { opts.multipart[i].body = body; }); - + that.request(opts, opt_callback, true); } });