2010-10-07 78 views
0

對於OpenID身份驗證,我使用的是「PHP OpenID庫」(http://www.janrain.com/openid-enabled)。在圖書館的幫助下,如何獲得更多信息(暱稱,電子郵件)?PHP OpenID geting暱稱和電子郵件

我有一些問題LightOpenID,當我問在Yandex的LightOpenID-電子郵件>有效期爲假(

class Ncw_OpenID extends LightOpenID 
{ 
    const OPENID_MODE_CANCEL = 'cancel'; 

    public function __construct() 
    { 
     parent::__construct(); 
     $this->required = array('namePerson/friendly', 'contact/email'); 
     $this->optional = array('contact/email'); 
     //$this->returnUrl = 'http://' . SITE_URI . '/users/login'; 
    } 

    public function getAttributes() { 
     $attr = parent::getAttributes(); 
     $newAttr = array(); 
     foreach ($attr as $key => $value) { 
      if (isset(parent::$ax_to_sreg[$key])) $key = parent::$ax_to_sreg[$key]; 
      $newAttr[$key] = $value; 
     } 
     return $newAttr; 
    } 
} 

class Users_IndexController extends Zend_Controller_Action 
{ 
    public function loginAction() 
    { 
     $openIDMode = $this->_request->getParam('openid_mode'); 
     $openID = new Ncw_OpenID(); 
     $form = new Users_Form_Login(array('action' => $this->view->url(array(), 'openIDLogin'))); 

     if (null === $openIDMode) { 

      if ($this->_request->isPost() && $form->isValid($_POST)) { 
       $openID->identity = $form->getValue('openIDUri'); 
       $this->_redirect($openID->authUrl()); 
       exit(); 
      } 
      $this->view->content = $form; 
     } elseif (Ncw_OpenID::OPENID_MODE_CANCEL == $openIDMode) { 
      $this->view->content = 'Cancel'; 
     } else { 
      if ($openID->validate()) { 
       $this->view->content = 'Valid: ' . $openID->identity . ' = ' . var_export($openID->getAttributes(), true); 
      } else { 
       $this->view->content = 'Not Valid'; 
      } 
      $this->view->content .= $form; 
     } 
    } 

    public function logoutAction() 
    { 
     // action body 
    } 
} 

回答

1

Here是一個不完整的例子,它是不完整的意義上,它僅使用SREG,並不是每個提供商都支持它(例如Google只支持AX)

據我所知,php-openid並沒有提供一種簡單的方法來自動檢測服務器支持什麼,並相應地使用AX或SREG 。

有關更多信息,我會查看源代碼的註釋或README建議,使用phpdoc從它們生成文檔。

但是,如果您可以切換庫,我建議LightOpenID。它更容易使用,並自動執行大多數事情(與php-openid相反)。

+0

謝謝,需要試試) – ErgallM 2010-10-08 08:19:53

+0

@ErgalIM:我不明白你的意見,請你澄清一下你的意思? (尤其是,什麼是「是」的答案?) – Mewp 2010-10-13 16:27:26

+0

錯過了評論) – ErgallM 2010-10-14 13:30:22