Permalink
Browse files

Minor fixes to Evan's work on Issue #97 ( tokenByTokenAndConsumer )

'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 2edefe75475c0c50d7a1d2174e4c1dc6a05f490a
Showing with 14 additions and 8 deletions.
  1. +14 −8 lib/auth.strategies/oauth/_oauthservices.js
@@ -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);

1 comment on commit 2edefe7

@evanp

This comment has been minimized.

Show comment Hide comment
@evanp

evanp May 16, 2012

Contributor

I like that.

Contributor

evanp commented on 2edefe7 May 16, 2012

I like that.

Please sign in to comment.