files/api/user/services/grant.js
function getProfile(provider, access_token, callback) {
  let fields;
  switch (provider) {
    case 'facebook':
      facebook.query().get('me?fields=name,email').auth(access_token).request(function (err, res, body) {
        if (err) {
          callback(err);
        } else {
          callback(null, {
            username: body.name,
            email: body.email
          });
        }
      });
      break;
    case 'google':
      google.query('plus').get('people/me').auth(access_token).request(function (err, res, body) {
        if (err) {
          callback(err);
        } else {
          callback(null, {
            username: body.displayName,
            email: body.emails[0].value
          });
        }
      });
      break;
    case 'github':
      github.query().get('user').auth(access_token).request(function (err, res, body) {
        if (err) {
          callback(err);
        } else {
          callback(null, {
            username: body.login,
            email: body.email
          });
        }
      });
      break;
    case 'linkedin2':
      fields = [
        'public-profile-url', 'email-address'
      ];
      linkedin.query().select('people/~:(' + fields.join() + ')?format=json').auth(access_token).request(function (err, res, body) {
        if (err) {
          callback(err);
        } else {
          callback(null, {
            username: substr(body.publicProfileUrl.lastIndexOf('/') + 1),
            email: body.emailAddress
          });
        }
      });
      break;
    default:
      callback({
        message: 'Unknown provider.'
      });
      break;
  }
}
function getProfile(provider, access_token, callback) {
  let fields;
  switch (provider) {
    case 'facebook':
      facebook.query().get('me?fields=name,email').auth(access_token).request(function (err, res, body) {
        if (err) {
          callback(err);
        } else {
          callback(null, {
            username: body.name,
            email: body.email
          });
        }
      });
      break;
    case 'google':
      google.query('plus').get('people/me').auth(access_token).request(function (err, res, body) {
        if (err) {
          callback(err);
        } else {
          callback(null, {
            username: body.displayName,
            email: body.emails[0].value
          });
        }
      });
      break;
    case 'github':
      github.query().get('user').auth(access_token).request(function (err, res, body) {
        if (err) {
          callback(err);
        } else {
          callback(null, {
            username: body.login,
            email: body.email
          });
        }
      });
      break;
    case 'linkedin2':
      fields = [
        'public-profile-url', 'email-address'
      ];
      linkedin.query().select('people/~:(' + fields.join() + ')?format=json').auth(access_token).request(function (err, res, body) {
        if (err) {
          callback(err);
        } else {
          callback(null, {
            username: substr(body.publicProfileUrl.lastIndexOf('/') + 1),
            email: body.emailAddress
          });
        }
      });
      break;
    default:
      callback({
        message: 'Unknown provider.'
      });
      break;
  }
}
function getProfile ( provider , access_token , callback ) { let fields ; switch ( provider ) { case 'facebook' : facebook . query ( ) . get ( 'me?fields=name,email' ) . auth ( access_token ) . request ( function ( err , res , body ) { if ( err ) { callback ( err ) ; } else { callback ( null , { username : body . name , email : body . email } ) ; } } ) ; break ; case 'google' : google . query ( 'plus' ) . get ( 'people/me' ) . auth ( access_token ) . request ( function ( err , res , body ) { if ( err ) { callback ( err ) ; } else { callback ( null , { username : body . displayName , email : body . emails [ 0 ] . value } ) ; } } ) ; break ; case 'github' : github . query ( ) . get ( 'user' ) . auth ( access_token ) . request ( function ( err , res , body ) { if ( err ) { callback ( err ) ; } else { callback ( null , { username : body . login , email : body . email } ) ; } } ) ; break ; case 'linkedin2' : fields = [ 'public-profile-url' , 'email-address' ] ; linkedin . query ( ) . select ( 'people/~:(' + fields . join ( ) + ')?format=json' ) . auth ( access_token ) . request ( function ( err , res , body ) { if ( err ) { callback ( err ) ; } else { callback ( null , { username : substr ( body . publicProfileUrl . lastIndexOf ( '/' ) + 1 ) , email : body . emailAddress } ) ; } } ) ; break ; default : callback ( { message : 'Unknown provider.' } ) ; break ; } }
Helper to get profiles

@param {String}   provider
@param {Function} callback
Helper to get profiles