Zend OpenId 2.0 支持

发布于 2024-10-22 01:07:12 字数 2680 浏览 1 评论 0原文

我需要通过 OpenId 注册用户(例如 google)
但它不起作用!

我已经看到一些主题:
http://framework.zend.com/issues/browse/ZF-6905
Zend OpenId 和 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) 则一切正常,但我需要用户信息进行注册

而且我还使用此问题中的 Zend_OpenId_Consumer http://framework.zend.com/issues/browse/ZF-6905,因为使用本机 Zend_OpenId_Consumer $consumer->verify($data, $id) 这不起作用

另外建议使用一些代理,或其他与 openid 一起使用的库不提供。

I need to signup a user by OpenId (for example google)
But it is not working!

I have already see some topics:
http://framework.zend.com/issues/browse/ZF-6905
Zend OpenId and Google
And others..

But all of that is not works!

I need to fetch user info (such as login or email) but if I use like this

// $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;
}

And the output is:

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)

Please help: how can i fetch user info from openid server (for example google) for signup user?

If I use $consumer->verify($data, $id) than all ok, but I need user info for signup

And also I use Zend_OpenId_Consumer from this issue http://framework.zend.com/issues/browse/ZF-6905, because with native Zend_OpenId_Consumer $consumer->verify($data, $id) this is not works

Also suggestions to use some brokers, or other libs working with openid not offer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苯莒 2024-10-29 01:07:12

Akeem Philbert 有一篇文章和一些文件,您可以使用它们来扩展 ZF 中的 OpenID 实现,以至少支持将 OpenID 与 Google 结合使用。

http://ak33m.com/?p=71

还有一篇关于让 ZF 上使用 Facebook 和 Twitter

http://shortrecipes .blogspot.com/2011/02/example-of-openid-facebook-and-twitter.html

正如 @takeshin 所指出的,遗憾的是,ZF 尚未完全支持 OpenID 2.0。

Akeem Philbert has a post and some files you can use to extend the OpenID implementation in ZF to support at least using OpenID with Google.

http://ak33m.com/?p=71

There is also a blog post about getting ZF to work with Facebook and Twitter at

http://shortrecipes.blogspot.com/2011/02/example-of-openid-facebook-and-twitter.html

As @takeshin has pointed out, sadly, ZF doesn't not yet fully support OpenID 2.0.

霞映澄塘 2024-10-29 01:07:12

AFAIK Zend Framework 尚未完全支持 OpenID 2.0。

请参阅此 ZF 问题:

您可以使用其他外部库:

AFAIK Zend Framework does not support OpenID 2.0 fully yet.

Please refer to this ZF issue:

http://www.framework.zend.com/issues/browse/ZF-6905?page=com.atlassian.streams.streams-jira-plugin%3Aactivity-stream-issue-tab

You may use other, external libraries instead:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文