Skip to content

Batch Requests fail to refresh access token #99

Description

@abecks

I noticed that while making batch requests, 401 Unauthorized responses are not caught in the current handler because they return an HTTP status code of 200, and each error is presented in a JSON array in the response body.

I managed to temporarily fix this by changing the OAuth2Client.prototype.request function:

from:

var hasAuthError = (res.statusCode == 401 || res.statusCode == 403)

to:

// TODO: Check if it's not userRateLimitExceeded
var hasAuthError = 
    (res.statusCode == 401 || res.statusCode == 403)
    || body.indexOf('401 Unauthorized') >= 0; // batch requests

A deep copy of the request options must be cached:

from:

var that = this;
var credentials = this.credentials;

to:

var optsClone = JSON.parse(JSON.stringify(opts)); 
var that = this;
var credentials = this.credentials;

and used for the request when it is re-played

from:

var tokens = result;
tokens.refresh_token = credentials.refresh_token;
that.credentials = tokens;
that.request(opts, opt_callback, true);

to:

var tokens = result;
tokens.refresh_token = credentials.refresh_token;
that.credentials = tokens;
that.request(optsClone, opt_callback, true);

I'm sure there is probably a more elegant way of fixing this instead of using "indexOf", but this should help people having the same problem for now.

Activity

  1. rakyll commented on Oct 30, 2013

    @rakyll
    Contributor

    OData batches implemented by this client library is quite experimental. As long as, I don't have a native http implementation to parse the multipart segments, batch requests are not that useful at all. So, I'm on hold for now to fix known error handling issues with batch requests.

  2. ryanseys commented on Jul 22, 2014

    @ryanseys
    Contributor

    Closing as WONTFIX. In version 1.0.0 we have removed support for batch requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions