2010-11-16 58 views
1

我正在使用LightOpenID,我試圖獲得此gmail身份驗證的屬性,但它似乎沒有返回任何關於我的個人帳戶並且我沒有任何錯誤。我對OpenID非常陌生,希望有人能幫助我解決之前的問題。從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; 
    } 

回答

1

谷歌的答案只有到所需要的參數,完全無視那些可選。

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

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

所以namePersoncontact/postalCode/home將無法​​正常工作。

以上信息特定於Google,與LightOpenID本身完全無關。

至於圖書館,我建議反對調用$ lightOpenId-> validate()兩次。每次調用它時,它都會向提供商發送請求,可能會拒絕第二個請求。

+0

啊......我明白了。謝謝! – Webnet 2010-11-17 14:02:13

+0

其實,'contact/country/home'不工作... – Webnet 2010-11-28 01:38:02

+0

@Webnet:的確,它似乎不起作用。我的信息基於[Google聯合登錄](http://code.google.com/apis/accounts/docs/OpenID.html)頁面,因此我認爲這些信息是正確的。 – Mewp 2010-11-28 11:21:24

2
$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());