【问题标题】:Getting attributes from GMail - OpenID Authentication从 GMail 获取属性 - OpenID 身份验证
【发布时间】:2010-11-16 16:53:30
【问题描述】:

我正在使用 LightOpenID,我正在尝试获取此 gmail 身份验证的属性,但它似乎没有在我的个人帐户上返回任何内容,并且我没有收到任何错误。我对 OpenID 很陌生,希望有人能帮我找出以前做过这件事的人。

我在 validate() 上指定字段并使用 process() 返回它们

我使用的是 OpenID 网址:https://www.google.com/accounts/o8/id

    public function show () {
        if ($this->site->tru->post->isRequest() || !$this->site->tru->get->isEmpty('openid_mode')) {
            require_once $this->site->tru->config->get('root.path').'/lib/php/openid.php';
            $this->lightOpenId = new LightOpenID;
            if ($this->validate() || $this->lightOpenId->validate()) {
                $this->process();
            }
        }

        $this->site->addCss('account/login.css');

        $this->site->addJs('account/login.js');

        echo $this->site->tru->display->getTemplate('/site/account/login.tpl');
    }

    public function process () {
        if ($this->lightOpenId->validate()) {
            echo '<pre>'.print_r($this->lightOpenId).'
'.print_r($this->lightOpenId->getAttributes()).'</pre>';
        }
    }

    public function validate () {
        if (!$this->site->tru->post->isEmpty('openid_url')) {
            $this->lightOpenId->identity = $this->site->tru->post->get('openid_url');
            $this->lightOpenId->optional = array('contact/email', 'namePerson', 'contact/postalCode/home', 'contact/country/home');

            header('Location: '.$this->lightOpenId->authUrl());
        }

        return count($this->error) == 0;
    }

【问题讨论】:

    标签: openid openid-provider


    【解决方案1】:
    $openid->identity = 'https://www.google.com/accounts/o8/';
    
    // use the following line to obtain the required details. These are the only details that google mail provides. This is for lightopenid.
    $openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last'); 
    
    header('Location: ' . $openid->authUrl());
    

    【讨论】:

      【解决方案2】:

      Google 只回答必需的参数,完全忽略可选参数。

      另外,它只能返回以下属性:

      contact/country/home
      contact/email
      namePerson/first
      namePerson/last
      pref/language
      

      所以namePersoncontact/postalCode/home 不起作用。

      以上信息是谷歌专有的,与 LightOpenID 本身完全无关。

      至于库,我建议不要调用 $lightOpenId->validate() 两次。每次调用它时,它都会向可能拒绝第二个请求的提供者发送一个请求。

      【讨论】:

      • @Webnet:确实,它似乎不起作用。我的信息基于Google Federated Login 页面,所以我认为那里的信息是正确的。
      猜你喜欢
      • 2021-09-07
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 2023-04-08
      • 2011-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多