代码之家  ›  专栏  ›  技术社区  ›  Ben

从GMail-OpenID身份验证获取属性

  •  1
  • Ben  · 技术社区  · 14 年前

    我正在使用LightOpenID,我正在尝试获取此gmail身份验证的属性,但它似乎没有返回任何关于我的个人帐户的信息,我没有收到任何错误。我对OpenID很陌生,希望有人能帮我解决以前的问题。

    我在指定 validate() 把它们还回去 process()

    我正在使用OpenID URL: 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;
        }
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Mewp    14 年前

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

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

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

    所以 namePerson contact/postalCode/home 不会起作用的。

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

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

        2
  •  2
  •   Floccinaucinihilipilification.    14 年前
    $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());