2011-03-15 133 views
2

我需要通過OpenId註冊用戶(例如谷歌)
但它不工作!Zend OpenId 2.0支持

我已經看到一些主題:
http://framework.zend.com/issues/browse/ZF-6905
Zend OpenId and Google
而其他..

但所有這一切是不是作品!

我需要獲取用戶信息(如賬號或電子郵件),但如果我用這樣的

// $data['openidIdentifier'] = 'https://www.google.com/accounts/o8/id'; 
public function loginByOpenIdAction() { 
    $request = $this->getRequest(); 
    $form = new Application_Form_UsersLoginByOpenId(); 

    $this->view->headTitle('Login by OpenId'); 

    if ($request->isPost()) { 
     $data = $request->getPost(); 
     if ($form->isValid($data)) { 
      $consumer = new Zend_OpenId_Consumer(); 
      $backUrl = $this->getHelper('Url')->url(array('controller' => 'users', 'action' => 'signup-from-open-id')); 

      if (!$consumer->login($data['openidIdentifier'], $backUrl)) { 
       $this->view->error = 'Can`t connect to OpenId provider'; 
      } 
     } 
    } 

    $this->view->form = $form; 
} 

public function signupFromOpenIdAction() { 
    $consumer = new Zend_OpenId_Consumer(); 
    $data = &$_GET; 

    $sreg = new Zend_OpenId_Extension_Sreg(array(
     'nickname' => true, 
     'email' => false, 
     'fullname' => false), null, 1.1 
    ); 

    if ($consumer->verify($data, $id, $sreg)) { 
     $properties = $sreg->getProperties(); 
     var_dump($properties); 
     var_dump('allow', $id); 
    } else { 
     var_dump('deny', $id, $consumer); 
    } 
    die; 
} 

,輸出是:

 
string 'deny' (length=4) 
string 'https://www.google.com/accounts/o8/id?id=fooBarFooBar' (length=80) 
object(Zend_OpenId_Consumer)[61] 
    protected '_storage' => 
    object(Zend_OpenId_Consumer_Storage_File)[62] 
     private '_dir' => string '/tmp/azat/openid/consumer' (length=25) 
    protected '_dumbMode' => boolean false 
    protected '_cache' => 
    array 
     empty 
    private '_httpClient' => null 
    private '_session' => null 
    private '_error' => string 'Extension::parseResponse failure' (length=32) 

請幫助:我如何可以獲取用戶來自openid服務器的信息(例如谷歌)註冊用戶?

如果我使用$consumer->verify($data, $id)高於一切OK,但我需要註冊用戶信息

而且我也用Zend_OpenId_Consumer從本期http://framework.zend.com/issues/browse/ZF-6905,因爲與當地Zend_OpenId_Consumer $consumer->verify($data, $id)這不是工作

還建議使用一些經紀人或其他使用openid的庫不提供。

+0

也許這將有助於:http://stackoverflow.com/questions/5310860/zend-framework-open-id-extensions-with-google/5311378#5311378 – Marcin 2011-03-15 12:06:46

+0

@ nvoyageur,不,因爲我已經說過需要建立在功能。我決定等待內置類補丁。 – azat 2011-03-31 19:53:49

回答

1
+0

我寫的是我不會使用外部庫 – azat 2011-03-15 11:47:15

+0

@azat它還不在ZF中,所以除了自己寫或修復由takehin引發的問題之外別無選擇 – 2011-03-15 15:55:42