Skip to content

Commit

Permalink
Minor fixes to Evan's work on Issue #97 ( tokenByTokenAndConsumer )
Browse files Browse the repository at this point in the history
'Cached' which method ( tokenByTokenAndConsumer or tokenByConsumer)
the provider is providing, and stopped testing for the token methods
for *each* required method in the loop (typo.)
  • Loading branch information
ciaranj committed May 16, 2012
1 parent 78fc1ae commit 2edefe7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/auth.strategies/oauth/_oauthservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,25 @@ exports.OAuthServices= function(provider, legs) {
**/
requiredMethods.forEach(function(method) {
if(!(Object.prototype.toString.call(provider[method]) === "[object Function]")) throw Error("Data provider must provide the methods [" + requiredMethods.join(', ') + "]");

if(this.legs == 3 &&
!(Object.prototype.toString.call(provider.tokenByConsumer) === "[object Function]") &&
!(Object.prototype.toString.call(provider.tokenByTokenAndConsumer) === "[object Function]")) {
throw new Error("Data provider must provide either tokenByConsumer() or tokenByTokenAndConsumer()");
}
});

if(this.legs == 3) {
this.providerProvidesTokenByConsumer= (Object.prototype.toString.call(provider.tokenByConsumer) === "[object Function]");
this.providerProvidesTokenByTokenAndConsumer= (Object.prototype.toString.call(provider.tokenByTokenAndConsumer) === "[object Function]");
if( !this.providerProvidesTokenByConsumer && !this.providerProvidesTokenByTokenAndConsumer) {
throw new Error("Data provider must provide either tokenByConsumer() or tokenByTokenAndConsumer()");
} else {

}
}


};

exports.OAuthServices.prototype.tokenByTokenAndConsumer= function(token, consumerKey, callback) {
if (Object.prototype.toString.call(this.provider.tokenByTokenAndConsumer) === "[object Function]") {
if (this.providerProvidesTokenByTokenAndConsumer) {
this.provider.tokenByTokenAndConsumer(token, consumerKey, callback);
} else if (Object.prototype.toString.call(this.provider.tokenByConsumer) === "[object Function]") {
} else if (this.providerProvidesTokenByConsumer) {
this.provider.tokenByConsumer(consumerKey, callback);
} else {
callback(new Error("provider: must provide either tokenByConsumer() or tokenByTokenAndConsumer()"), null);
Expand Down

1 comment on commit 2edefe7

@evanp
Copy link
Contributor

@evanp evanp commented on 2edefe7 May 16, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that.

Please sign in to comment.