PHP OpenID geting nickname & email -
for openid authentication i'm using "php openid library" (http://www.janrain.com/openid-enabled). how, of library, ask additional information (nickname, email)?
i've got problems lightopenid, when ask email @ 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 $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 } }
here incomplete example. it's incomplete in sense it's using sreg, , not every provider supports (for example, google supports ax).
as far know, php-openid doesn't offer simple way automatically detect server support , accordingly use ax or sreg.
for more information, i'd @ source code's comments or readme suggests, generate documentation them, using phpdoc.
however, if can switch libraries, i'd recommend lightopenid. it's easier use , things automatically (contrary php-openid).
Comments
Post a Comment