Skip to content
Browse files

Merge branch 'release/0.3.2'

  • Loading branch information...
2 parents f009161 + 002fdea commit 2de5fa7a69dc634381e27f5dfb6e42e50ade36dd @stomita committed Oct 19, 2012
Showing with 25 additions and 12 deletions.
  1. +11 −9 lib/connection.js
  2. +1 −1 package.json
  3. +13 −2 test/salesforce.test.js
View
20 lib/connection.js
@@ -54,9 +54,8 @@ Connection.prototype.initialize = function(options) {
}
this.accessToken = options.sessionId || options.accessToken || this.accessToken;
this.refreshToken = options.refreshToken || this.refreshToken;
- if (this.oauth2 && this.refreshToken) {
- this.removeAllListeners('auth');
- this.once('auth', _.bind(this._refresh, this));
+ if (this.refreshToken && !this.oauth2) {
+ throw new Error("Refersh token is specified without oauth2 client information");
}
this.maxRequest = options.maxRequest || this.maxRequest || 10;
};
@@ -68,7 +67,11 @@ Connection.prototype.initialize = function(options) {
*/
Connection.prototype._request = function(params, callback, noContentResponse) {
var self = this;
- var onResume = function() {
+ var onResume = function(err) {
+ if (err) {
+ callback(err);
+ return;
+ }
self._request(params, callback, noContentResponse);
};
if (self.suspended) {
@@ -85,11 +88,11 @@ Connection.prototype._request = function(params, callback, noContentResponse) {
callback(err);
} else {
self.emit('response', response.statusCode, response.body, response);
- // if authorization required and auth handler is available
- if (response.statusCode === 401 && self.listeners('auth').length >= 0) {
+ // if authorization required, refresh when oauth2 info and refresh token is available
+ if (response.statusCode === 401 && self.oauth2 && self.refreshToken) {
self.suspended = true;
self.once('resume', onResume);
- self.emit('auth');
+ self._refresh();
return;
}
if (response.statusCode >= 400) {
@@ -130,10 +133,9 @@ Connection.prototype._refresh = function() {
instanceUrl : res.instance_url,
accessToken : res.access_token
});
- self.once('auth', _.bind(self._refresh, self));
}
self.suspended = false;
- self.emit('resume');
+ self.emit('resume', err);
});
};
View
2 package.json
@@ -4,7 +4,7 @@
"description": "Connecting Salesforce via RESTful API",
"keywords": [ "salesforce", "salesforce.com", "sfdc", "force.com", "database.com" ],
"homepage": "http://github.com/stomita/node-salesforce",
- "version": "0.3.1",
+ "version": "0.3.2",
"repository": {
"type": "git",
"url": "git://github.com/stomita/node-salesforce.git"
View
15 test/salesforce.test.js
@@ -398,10 +398,21 @@ vows.describe("salesforce").addBatch({
assert.isArray(results[0].records);
assert.isArray(results[1].sobjects);
assert.isArray(results[2].fields);
- }
+ },
+ ", then again expire access token and expire refresh token" : {
+ topic : function() {
+ conn.accessToken = "invalid access token";
+ conn.refreshToken = "invalid refresh token";
+ conn.query("SELECT Id FROM User", this.callback);
+ },
+
+ "should return error response" : function(err, user) {
+ assert.isObject(err);
+ assert.equal("invalid_grant", err.error);
+ }
- }}}}}}}
+ }}}}}}}}
}).export(module);

0 comments on commit 2de5fa7

Please sign in to comment.
Something went wrong with that request. Please try again.