lib/strategy.js
function OAuthStrategy(options, verify) {
  if (typeof options == 'function') {
    verify = options;
    options = undefined;
  }
  options = options || {};
  
  if (!verify) { throw new TypeError('OAuthStrategy requires a verify callback'); }
  if (!options.requestTokenURL) { throw new TypeError('OAuthStrategy requires a requestTokenURL option'); }
  if (!options.accessTokenURL) { throw new TypeError('OAuthStrategy requires a accessTokenURL option'); }
  if (!options.userAuthorizationURL) { throw new TypeError('OAuthStrategy requires a userAuthorizationURL option'); }
  if (!options.consumerKey) { throw new TypeError('OAuthStrategy requires a consumerKey option'); }
  if (options.consumerSecret === undefined) { throw new TypeError('OAuthStrategy requires a consumerSecret option'); }
  
  passport.Strategy.call(this);
  this.name = 'oauth';
  this._verify = verify;
  
  // NOTE: The _oauth property is considered "protected".  Subclasses are
  //       allowed to use it when making protected resource requests to retrieve
  //       the user profile.
  this._oauth = new OAuth(options.requestTokenURL, options.accessTokenURL,
                          options.consumerKey,  options.consumerSecret,
                          '1.0', null, options.signatureMethod || 'HMAC-SHA1',
                          null, options.customHeaders);
  
  this._userAuthorizationURL = options.userAuthorizationURL;
  this._callbackURL = options.callbackURL;
  this._key = options.sessionKey || 'oauth';
  this._requestTokenStore = options.requestTokenStore || new SessionRequestTokenStore({ key: this._key });
  this._trustProxy = options.proxy;
  this._passReqToCallback = options.passReqToCallback;
  this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile;
}
function OAuthStrategy(options, verify) {
  if (typeof options == 'function') {
    verify = options;
    options = undefined;
  }
  options = options || {};
  
  if (!verify) { throw new TypeError('OAuthStrategy requires a verify callback'); }
  if (!options.requestTokenURL) { throw new TypeError('OAuthStrategy requires a requestTokenURL option'); }
  if (!options.accessTokenURL) { throw new TypeError('OAuthStrategy requires a accessTokenURL option'); }
  if (!options.userAuthorizationURL) { throw new TypeError('OAuthStrategy requires a userAuthorizationURL option'); }
  if (!options.consumerKey) { throw new TypeError('OAuthStrategy requires a consumerKey option'); }
  if (options.consumerSecret === undefined) { throw new TypeError('OAuthStrategy requires a consumerSecret option'); }
  
  passport.Strategy.call(this);
  this.name = 'oauth';
  this._verify = verify;
  
  // NOTE: The _oauth property is considered "protected".  Subclasses are
  //       allowed to use it when making protected resource requests to retrieve
  //       the user profile.
  this._oauth = new OAuth(options.requestTokenURL, options.accessTokenURL,
                          options.consumerKey,  options.consumerSecret,
                          '1.0', null, options.signatureMethod || 'HMAC-SHA1',
                          null, options.customHeaders);
  
  this._userAuthorizationURL = options.userAuthorizationURL;
  this._callbackURL = options.callbackURL;
  this._key = options.sessionKey || 'oauth';
  this._requestTokenStore = options.requestTokenStore || new SessionRequestTokenStore({ key: this._key });
  this._trustProxy = options.proxy;
  this._passReqToCallback = options.passReqToCallback;
  this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile;
}
function OAuthStrategy ( options , verify ) { if ( typeof options == 'function' ) { verify = options ; options = undefined ; } options = options || { } ; if ( ! verify ) { throw new TypeError ( 'OAuthStrategy requires a verify callback' ) ; } if ( ! options . requestTokenURL ) { throw new TypeError ( 'OAuthStrategy requires a requestTokenURL option' ) ; } if ( ! options . accessTokenURL ) { throw new TypeError ( 'OAuthStrategy requires a accessTokenURL option' ) ; } if ( ! options . userAuthorizationURL ) { throw new TypeError ( 'OAuthStrategy requires a userAuthorizationURL option' ) ; } if ( ! options . consumerKey ) { throw new TypeError ( 'OAuthStrategy requires a consumerKey option' ) ; } if ( options . consumerSecret === undefined ) { throw new TypeError ( 'OAuthStrategy requires a consumerSecret option' ) ; } passport . Strategy . call ( this ) ; this . name = 'oauth' ; this . _verify = verify ; // NOTE: The _oauth property is considered "protected".  Subclasses are //       allowed to use it when making protected resource requests to retrieve //       the user profile. this . _oauth = new OAuth ( options . requestTokenURL , options . accessTokenURL , options . consumerKey , options . consumerSecret , '1.0' , null , options . signatureMethod || 'HMAC-SHA1' , null , options . customHeaders ) ; this . _userAuthorizationURL = options . userAuthorizationURL ; this . _callbackURL = options . callbackURL ; this . _key = options . sessionKey || 'oauth' ; this . _requestTokenStore = options . requestTokenStore || new SessionRequestTokenStore ( { key : this . _key } ) ; this . _trustProxy = options . proxy ; this . _passReqToCallback = options . passReqToCallback ; this . _skipUserProfile = ( options . skipUserProfile === undefined ) ? false : options . skipUserProfile ; }
Creates an instance of `OAuthStrategy`.

The OAuth authentication strategy authenticates requests using the OAuth
protocol.

OAuth provides a facility for delegated authentication, whereby users can
authenticate using a third-party service such as Twitter.  Delegating in this
manner involves a sequence of events, including redirecting the user to the
third-party service for authorization.  Once authorization has been obtained,
the user is redirected back to the application and a token can be used to
obtain credentials.

Applications must supply a `verify` callback, for which the function
signature is:

function(token, tokenSecret, profile, cb) { ... }

The verify callback is responsible for finding or creating the user, and
invoking `cb` with the following arguments:

done(err, user, info);

`user` should be set to `false` to indicate an authentication failure.
Additional `info` can optionally be passed as a third argument, typically
used to display informational messages.  If an exception occured, `err`
should be set.

Options:

- `requestTokenURL`       URL used to obtain an unauthorized request token
- `accessTokenURL`        URL used to exchange a user-authorized request token for an access token
- `userAuthorizationURL`  URL used to obtain user authorization
- `consumerKey`           identifies client to service provider
- `consumerSecret`        secret used to establish ownership of the consumer key
- 'signatureMethod'       signature method used to sign the request (default: 'HMAC-SHA1')
- `callbackURL`           URL to which the service provider will redirect the user after obtaining authorization
- `passReqToCallback`     when `true`, `req` is the first argument to the verify callback (default: `false`)

Examples:

passport.use(new OAuthStrategy({
requestTokenURL: 'https://www.example.com/oauth/request_token',
accessTokenURL: 'https://www.example.com/oauth/access_token',
userAuthorizationURL: 'https://www.example.com/oauth/authorize',
consumerKey: '123-456-789',
consumerSecret: 'shhh-its-a-secret'
callbackURL: 'https://www.example.net/auth/example/callback'
},
function(token, tokenSecret, profile, cb) {
User.findOrCreate(..., function (err, user) {
cb(err, user);
});
}
));

@constructor
@param {Object} options
@param {Function} verify
@api public
Creates an instance of OAuthStrategy .