【问题标题】:Oauth/Hello.js returns empty "name" fieldsOauth/Hello.js 返回空的“名称”字段
【发布时间】:2015-09-29 17:30:30
【问题描述】:

我正在使用 hello.js 来允许用户登录我的网站。到目前为止,登录 google 工作正常,但我有一个特定用户收到错误。
他们有一个非 gmail 电子邮件地址,但通常可以使用它登录谷歌服务(想想“thisguy@companyname.net”)。当他登录时,返回的对象有几个表示他的名字的变量的空白字段(“name”、“last_name”、“first_name”、“displayName”都是空白的)。结果是,当他登录时,他收到一条热烈欢迎的“欢迎 [object Object]”消息,而我的应用程序没有可使用的名称信息。下面是我用来实现 hello.js 的代码。但是,我很困惑这是否是我的代码有问题,或者我通过谷歌开发者控制台设置的方式,或者只是与他的帐户的性质有关。

      hello.on('auth.login', function(auth) {
              // Call user information, for the given network
              hello(auth.network).api('/me').then(function(r) {
                      // Inject it into the container
                      $("#div" + auth.network).css('visibility', 'visible'); //reveal div where prof is displayed
                      $("#div" + auth.network).css("display", "block");
                      var label = document.getElementById('profile_' + auth.network);
                      label.innerHTML = '<div style="padding:10px;"><img id="profilepic" src="' + r.thumbnail + '" /><br>Welcome ' + r.name + '</div>';
                      console.log("Returned object from sos: ",r);
                      console.log(r.name," from ",auth.network);
                      sos = auth.network;
                      sos_name = r.name ;
              });
      });


      hello.init({
             facebook: FACEBOOK_CLIENT_ID,
             google: GOOGLE_CLIENT_ID,
      });

下面是console.log在上面输出“r”时的输出。我用 REDACTED 替换了一些字段,以防它包含任何敏感信息。

显示名称“”

etag ""已删除""

名字“”

id“已编辑”

图像对象 { url="https://lh3.googleuserco...rscbv5M/photo.jpg?sz=50",
isDefault=true}

isPlusUser 错误

种类“plus#person”

语言“en”

姓氏“”

名称对象 { familyName="", givenName=""}

objectType "人"

图片“https://lh3.googleuserco...rscbv5M/photo.jpg?sz=50

缩略图“https://lh3.googleuserco...rscbv5M/photo.jpg?sz=50

验证为假

请注意,我已使用其他将 isPlusUser 设置为 false 的 Google 帐户登录,并且它们的名称信息仍然完整,因此我认为这不是危险信号。

【问题讨论】:

    标签: javascript oauth-2.0 google-oauth hello.js


    【解决方案1】:

    在某些情况下,从 Google 返回的名称字段可能是空字符串。我不确定这是否是一个错误,但无论哪种方式,你最好的做法是处理没有给出名字的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 2018-04-19
      • 1970-01-01
      • 2010-09-12
      • 2014-05-02
      相关资源
      最近更新 更多