2

在使用 EveryAuth NPM lib 向 google 进行 OAuth2.0 调用时,我正在尝试检索 google 电子邮件地址。有没有人设法让电子邮件使用 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('/'); 

范围:https ://www.googleapis.com/auth/userinfo.email导致异常:

错误:错误 401(未找到)!!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} 谷歌

401. 这是一个错误。

您的请求中有错误。我们知道的就这些。

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

4

1 回答 1

1

根据谷歌的范围和api端点略有不同,这让我有点困惑。如果您将 google.js 更改为以下内容,则 google Auth2.0 api 将返回用户的电子邮件地址。

  .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;
  });
于 2011-11-05T13:54:50.597 回答