2
votes

I am attempting to retrieve the google email address when making an OAuth2.0 call to google, using EveryAuth NPM lib. Has anyone managed to get the email to return using EveryAuth?

everyauth.google
  .entryPath('/auth/google')
  .callbackPath('/auth/google/callback')
  .appId('216450162097.apps.googleusercontent.com')
  .appSecret('8b6yf2nznWHgAu7iKNyGn-0F')
  .scope(['https://www.googleapis.com/auth/userinfo.email'])
  .findOrCreateUser( function(session, userAttributes) {
    console.log(userAttributes);  })
  .redirectPath('/'); 

The scope: https://www.googleapis.com/auth/userinfo.email causes exception:

Error: Error 401 (Not Found)!!1 display:block;height:55px;margin:0 0 -7px;width:150px}* > #g{margin-left:-2px}#g img{visibility:hidden}* html #g img{visibility:visible}*+html #g img{visibility:visible} Google

401. That's an error.

There was an error in your request. That's all we know.

at [object Object].fail (/Users/thegoleffect/Documents/Projects/Spoondate/nitrous/node_modules/everyauth/lib/promise.js:50:15) at EventEmitter. (/Users/thegoleffect/Documents/Projects/Spoondate/nitrous/node_modules/everyauth/lib/modules/google.js:58:15) at EventEmitter.emit (events.js:67:17) at EventEmitter._respond (/Users/thegoleffect/Documents/Projects/Spoondate/nitrous/node_modules/everyauth/node_modules/restler/lib/restler.js:127:12) at EventEmitter._fireEvents (/Users/thegoleffect/Documents/Projects/Spoondate/nitrous/node_modules/everyauth/node_modules/restler/lib/restler.js:131:52) at /Users/thegoleffect/Documents/Projects/Spoondate/nitrous/node_modules/everyauth/node_modules/restler/lib/restler.js:115:19 at IncomingMessage. (/Users/thegoleffect/Documents/Projects/Spoondate/nitrous/node_modules/everyauth/node_modules/restler/lib/restler.js:205:5) at IncomingMessage. (/Users/thegoleffect/Documents/Projects/Spoondate/nitrous/node_modules/everyauth/node_modules/restler/lib/restler.js:113:32) at IncomingMessage.emit (events.js:81:20) at HTTPParser.onMessageComplete (http.js:133:23)
1

1 Answers

1
votes

According to google the scope and the api end point are slightly different, which confused me a little. If you make the change to your google.js to the following, the google Auth2.0 api will return the email address of the user.

  .fetchOAuthUser( function (accessToken) {
    var promise = this.Promise();
    rest.get('https://www.googleapis.com/userinfo/email', {
      query: { oauth_token: accessToken, alt: 'json' }
    }).on('success', function (data, res) {
      console.log(data);
      var oauthUser = { email: data };
      promise.fulfill(oauthUser);
    }).on('error', function (data, res) {
      console.log(data);
      promise.fail(data);
    });
    return promise;
  });