Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/auth/oauth2client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -189,6 +189,14 @@ OAuth2Client.prototype.request =
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
var hasAuthError = res.statusCode == 401 || res.statusCode == 403;
Expand All @@ -203,6 +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) {
opts.multipart[i].body = body;
});

that.request(opts, opt_callback, true);

This comment was marked as spam.

This comment was marked as spam.

}
});
Expand Down