tags:

views:

32

answers:

1

For the OpenID authentication I'm using "PHP OpenID Library" (http://www.janrain.com/openid-enabled). How, with the help of this library, ask for additional information (nickname, email)?

I've got some problems with LightOpenID, when I ask email at yandex LightOpenID-> valid returns false(

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  A: 

Here is an incomplete example. It's incomplete in the sense that it's using only SREG, and not every provider supports it (for example, Google supports only AX).

As far as I know, php-openid doesn't offer a simple way to automatically detect what does the server support and accordingly use AX or SREG.

For more information, I'd look at the source code's comments or as the README suggests, generate documentation from them, using phpdoc.

However, if you can switch libraries, I'd recommend LightOpenID. It's easier to use and does most things automatically (contrary to php-openid).

Mewp
thanks, need to try)
ErgallM
@ErgalIM: I don't understand your comment, could you please clarify what do you mean? (especially, what does "yes" answer to?)
Mewp
missed commentary)
ErgallM
hi, i have some problem wth LightOpenID(( can you help me?
ErgallM
@ErgalIM: I'm the same person that maintains LightOpenID, so I'm already trying to help you through the bugtracker.
Mewp