lib/passport-familysearch/legacy-strategy.js
function Strategy(options, verify) {
  options = options || {};
  options.requestTokenURL = options.requestTokenURL || 'https://api.familysearch.org/identity/v2/request_token';
  options.accessTokenURL = options.accessTokenURL || 'https://api.familysearch.org/identity/v2/access_token';
  options.userAuthorizationURL = options.userAuthorizationURL || 'https://api.familysearch.org/identity/v2/authorize';
  options.signatureMethod = options.signatureMethod || 'PLAINTEXT';
  options.sessionKey = options.sessionKey || 'oauth:familysearch';

  OAuthStrategy.call(this, options, verify);
  this.name = 'familysearch';
  this._userProfileURL = options.userProfileURL || 'https://api.familysearch.org/identity/v2/user';
  
  // FamilySearch's OAuth implementation does not conform to the specification.
  // As a workaround, the underlying node-oauth functions are replaced in order
  // to deal with the idiosyncrasies.
  
  this._oauth._buildAuthorizationHeaders = function(orderedParameters) {
    var authHeader="OAuth ";
    if( this._isEcho ) {
      authHeader += 'realm="' + this._realm + '",';
    }

    for( var i= 0 ; i < orderedParameters.length; i++) {
       // Whilst the all the parameters should be included within the signature, only the oauth_ arguments
       // should appear within the authorization header.
       if( this._isParameterNameAnOAuthParameter(orderedParameters[i][0]) ) {
         if (orderedParameters[i][0] === 'oauth_signature') {
           // JDH: This is a workaround for FamilySearch's non-conformant OAuth
           //      implementation, which expects the `oauth_signature` value to
           //      be unencoded
           authHeader+= "" + this._encodeData(orderedParameters[i][0])+"=\""+ orderedParameters[i][1]+"\",";
         } else {
           authHeader+= "" + this._encodeData(orderedParameters[i][0])+"=\""+ this._encodeData(orderedParameters[i][1])+"\",";
         }
       }
    }

    authHeader= authHeader.substring(0, authHeader.length-1);
    return authHeader;
  }
  
  this._oauth._isParameterNameAnOAuthParameter= function(parameter) {
    // JDH: This is a workaround to force the `oauth_callback` parameter out of
    //      the Authorization header and into the request body, where
    //      FamilySearch expects to find it.
    if (parameter === 'oauth_callback') { return false; }
    var m = parameter.match('^oauth_');
    if( m && ( m[0] === "oauth_" ) ) {
      return true;
    }
    else {
      return false;
    }
  };
}
function Strategy(options, verify) {
  options = options || {};
  options.requestTokenURL = options.requestTokenURL || 'https://api.familysearch.org/identity/v2/request_token';
  options.accessTokenURL = options.accessTokenURL || 'https://api.familysearch.org/identity/v2/access_token';
  options.userAuthorizationURL = options.userAuthorizationURL || 'https://api.familysearch.org/identity/v2/authorize';
  options.signatureMethod = options.signatureMethod || 'PLAINTEXT';
  options.sessionKey = options.sessionKey || 'oauth:familysearch';

  OAuthStrategy.call(this, options, verify);
  this.name = 'familysearch';
  this._userProfileURL = options.userProfileURL || 'https://api.familysearch.org/identity/v2/user';
  
  // FamilySearch's OAuth implementation does not conform to the specification.
  // As a workaround, the underlying node-oauth functions are replaced in order
  // to deal with the idiosyncrasies.
  
  this._oauth._buildAuthorizationHeaders = function(orderedParameters) {
    var authHeader="OAuth ";
    if( this._isEcho ) {
      authHeader += 'realm="' + this._realm + '",';
    }

    for( var i= 0 ; i < orderedParameters.length; i++) {
       // Whilst the all the parameters should be included within the signature, only the oauth_ arguments
       // should appear within the authorization header.
       if( this._isParameterNameAnOAuthParameter(orderedParameters[i][0]) ) {
         if (orderedParameters[i][0] === 'oauth_signature') {
           // JDH: This is a workaround for FamilySearch's non-conformant OAuth
           //      implementation, which expects the `oauth_signature` value to
           //      be unencoded
           authHeader+= "" + this._encodeData(orderedParameters[i][0])+"=\""+ orderedParameters[i][1]+"\",";
         } else {
           authHeader+= "" + this._encodeData(orderedParameters[i][0])+"=\""+ this._encodeData(orderedParameters[i][1])+"\",";
         }
       }
    }

    authHeader= authHeader.substring(0, authHeader.length-1);
    return authHeader;
  }
  
  this._oauth._isParameterNameAnOAuthParameter= function(parameter) {
    // JDH: This is a workaround to force the `oauth_callback` parameter out of
    //      the Authorization header and into the request body, where
    //      FamilySearch expects to find it.
    if (parameter === 'oauth_callback') { return false; }
    var m = parameter.match('^oauth_');
    if( m && ( m[0] === "oauth_" ) ) {
      return true;
    }
    else {
      return false;
    }
  };
}
function Strategy ( options , verify ) { options = options || { } ; options . requestTokenURL = options . requestTokenURL || 'https://api.familysearch.org/identity/v2/request_token' ; options . accessTokenURL = options . accessTokenURL || 'https://api.familysearch.org/identity/v2/access_token' ; options . userAuthorizationURL = options . userAuthorizationURL || 'https://api.familysearch.org/identity/v2/authorize' ; options . signatureMethod = options . signatureMethod || 'PLAINTEXT' ; options . sessionKey = options . sessionKey || 'oauth:familysearch' ; OAuthStrategy . call ( this , options , verify ) ; this . name = 'familysearch' ; this . _userProfileURL = options . userProfileURL || 'https://api.familysearch.org/identity/v2/user' ; // FamilySearch's OAuth implementation does not conform to the specification. // As a workaround, the underlying node-oauth functions are replaced in order // to deal with the idiosyncrasies. this . _oauth . _buildAuthorizationHeaders = function ( orderedParameters ) { var authHeader = "OAuth " ; if ( this . _isEcho ) { authHeader += 'realm="' + this . _realm + '",' ; } for ( var i = 0 ; i < orderedParameters . length ; i ++ ) { // Whilst the all the parameters should be included within the signature, only the oauth_ arguments // should appear within the authorization header. if ( this . _isParameterNameAnOAuthParameter ( orderedParameters [ i ] [ 0 ] ) ) { if ( orderedParameters [ i ] [ 0 ] === 'oauth_signature' ) { // JDH: This is a workaround for FamilySearch's non-conformant OAuth //      implementation, which expects the `oauth_signature` value to //      be unencoded authHeader += "" + this . _encodeData ( orderedParameters [ i ] [ 0 ] ) + "=\"" + orderedParameters [ i ] [ 1 ] + "\"," ; } else { authHeader += "" + this . _encodeData ( orderedParameters [ i ] [ 0 ] ) + "=\"" + this . _encodeData ( orderedParameters [ i ] [ 1 ] ) + "\"," ; } } } authHeader = authHeader . substring ( 0 , authHeader . length - 1 ) ; return authHeader ; } this . _oauth . _isParameterNameAnOAuthParameter = function ( parameter ) { // JDH: This is a workaround to force the `oauth_callback` parameter out of //      the Authorization header and into the request body, where //      FamilySearch expects to find it. if ( parameter === 'oauth_callback' ) { return false ; } var m = parameter . match ( '^oauth_' ) ; if ( m && ( m [ 0 ] === "oauth_" ) ) { return true ; } else { return false ; } } ; }
Legacy `Strategy` constructor.

The FamilySearch legacy authentication strategy authenticates requests by delegating
to FamilySearch using the OAuth 1.0 protocol.

Applications must supply a `verify` callback which accepts a `token`,
`tokenSecret` and service-specific `profile`, and then calls the `done`
callback supplying a `user`, which should be set to `false` if the
credentials are not valid.  If an exception occured, `err` should be set.

Options:
- `consumerKey`     FamilySearch Developer Key
- `consumerSecret`  an empty string, as required by FamilySearch
- `callbackURL`     URL to which FamilySearch will redirect the user after obtaining authorization

Examples:

passport.use(new FamilySearchStrategy({
consumerKey: '123-456-789',
consumerSecret: ''
callbackURL: 'https://www.example.net/auth/familysearch/callback'
},
function(token, tokenSecret, profile, done) {
User.findOrCreate(..., function (err, user) {
done(err, user);
});
}
));

@param {Object} options
@param {Function} verify
@api public
Legacy Strategy constructor .