【发布时间】:2011-03-15 10:41:21
【问题描述】:
我需要通过 OpenId 注册用户(例如 google)
但它不起作用!
我已经看到了一些话题:
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;
}
输出是:
字符串“拒绝”(长度=4) 字符串“https://www.google.com/accounts/o8/id?id=fooBarFooBar”(长度=80) 对象(Zend_OpenId_Consumer)[61] 受保护的“_storage”=> 对象(Zend_OpenId_Consumer_Storage_File)[62] 私人'_dir' => 字符串'/tmp/azat/openid/consumer'(长度=25) protected '_dumbMode' => boolean false 受保护的“_cache”=> 大批 空的 私人'_httpClient' => null 私人'_session' => null private '_error' => string 'Extension::parseResponse failure' (length=32)请帮助:我如何从 openid 服务器(例如 google)获取注册用户的用户信息?
如果我使用$consumer->verify($data, $id) 就可以了,但我需要用户信息才能注册
而且我在这个问题http://framework.zend.com/issues/browse/ZF-6905 中使用 Zend_OpenId_Consumer,因为对于本机 Zend_OpenId_Consumer $consumer->verify($data, $id) 这是行不通的
还建议使用一些代理,或其他与 openid 一起工作的库不提供。
【问题讨论】:
-
@nvoyageur,不,正如我已经说过的需要内置功能。我决定等待内置类被修补。
标签: php zend-framework openid google-openid