Skip to content

Commit 1aa69bc

Browse files
committed
Merge pull request ciaranj#100 from evanp/ValidateNotReplayClient
Add validateNotReplayClient() method for OAuthDataProvider
2 parents e1c75d2 + b34b924 commit 1aa69bc

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

examples/in_memory_oauth_data_provider.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ OAuthDataProvider.prototype.validateNotReplay = function(accessToken, timestamp,
174174
callback(null, true);
175175
}
176176

177+
OAuthDataProvider.prototype.validateNotReplayClient = function(consumerKey, accessToken, timestamp, nonce, callback) {
178+
callback(null, true);
179+
}
180+
177181
/**
178182
Fetch user id based on token (used to identify user in oauth calls later)
179183
**/

lib/auth.strategies/oauth/_oauthservices.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function validateParameters(parameters, requiredParameters) {
4747

4848
exports.OAuthServices= function(provider, legs) {
4949
this.provider= provider;
50-
var requiredMethods = ['applicationByConsumerKey','validateNotReplay'];
50+
var requiredMethods = ['applicationByConsumerKey'];
5151
if (legs) {
5252
this.legs = legs;
5353
}
@@ -74,8 +74,14 @@ exports.OAuthServices= function(provider, legs) {
7474

7575
}
7676
}
77-
7877

78+
this.providerProvidesValidateNotReplay= (Object.prototype.toString.call(provider.validateNotReplay) === "[object Function]");
79+
this.providerProvidesValidateNotReplayClient= (Object.prototype.toString.call(provider.validateNotReplayClient) === "[object Function]");
80+
if( !this.providerProvidesValidateNotReplay && !this.providerProvidesValidateNotReplayClient) {
81+
throw new Error("Data provider must provide either validateNotReplay() or validateNotReplayClient()");
82+
} else {
83+
84+
}
7985
};
8086

8187
exports.OAuthServices.prototype.tokenByTokenAndConsumer= function(token, consumerKey, callback) {
@@ -214,13 +220,23 @@ exports.OAuthServices.prototype.authorize= function(request, protocol, callback)
214220

215221
// Given all the requestParameters and the next step function, error out if the a replay is detected
216222
var validateNotReplay = function(requestParameters, next) {
217-
self.provider.validateNotReplay(requestParameters.oauth_token, requestParameters.oauth_timestamp, requestParameters.oauth_nonce, function(err, result) {
218-
if(err) {
219-
callback(new errors.OAuthUnauthorizedError('Invalid / used nonce'), null);
220-
} else {
221-
next();
222-
}
223-
});
223+
if(self.providerProvidesValidateNotReplayClient) {
224+
self.provider.validateNotReplayClient(requestParameters.oauth_consumer_key, requestParameters.oauth_token, requestParameters.oauth_timestamp, requestParameters.oauth_nonce, function(err, result) {
225+
if(err) {
226+
callback(new errors.OAuthUnauthorizedError('Invalid / used nonce'), null);
227+
} else {
228+
next();
229+
}
230+
});
231+
} else {
232+
self.provider.validateNotReplay(requestParameters.oauth_token, requestParameters.oauth_timestamp, requestParameters.oauth_nonce, function(err, result) {
233+
if(err) {
234+
callback(new errors.OAuthUnauthorizedError('Invalid / used nonce'), null);
235+
} else {
236+
next();
237+
}
238+
});
239+
}
224240
};
225241

226242
var getApplicationByConsumerKey = function(consumer_key, next) {

0 commit comments

Comments
 (0)