-
class openidActions extends sfActions
-
{
-
/*
-
* ログインフォームを表示する処理
-
*/
-
public function executeLogin()
-
{
-
return sfView::SUCCESS;
-
}
-
/*
-
* ログインフォームからPostされたときのバリデート処理
-
*/
-
public function validateTryauth()
-
{
-
// OpenIDライブラリがNoticeを出してしまうため止めてます。
-
-
if ($er> E_STRICT) {
-
-
}
-
-
// openid_identifierがユーザの入力したURLが入っている。
-
$openid = $this->getRequestParameter('openid_identifier');
-
if (!$openid)
-
{
-
// エラー処理は手抜き。。
-
$this->getRequest()->setError('openid_identifier', 'error');
-
return false;
-
}
-
// openidの認証ファイルを格納するディレクトリ(DBにもできる)
-
$store_path = '/tmp/_php_tmp';
-
-
{
-
$this->getRequest()->setError('openid_identifier', 'error');
-
return false;
-
}
-
-
$store = new Auth_OpenID_FileStore($store_path);
-
$consumer = new Auth_OpenID_Consumer($store);
-
$auth_request = $consumer->begin($openid);
-
if (!$auth_request)
-
{
-
$this->getRequest()->setError('openid_identifier', 'error');
-
return false;
-
}
-
//認証時に属性が欲しい場合は指定する。
-
$sreg_request = Auth_OpenID_SRegRequest::build(
-
-
array('fullname',
'email'));
-
if ($sreg_request)
-
{
-
$auth_request->addExtension($sreg_request);
-
}
-
-
//OpenID1.0
-
if ($auth_request->shouldSendRedirect())
-
{
-
// trust_rootは認証されるサイトのURL、return_toは認証後にこちらにリダイレクトするURL
-
$redirect_url = $auth_request->redirectURL(
-
'http://sample.net/',
-
'http://sample.net/openid/finishauth');
-
if (Auth_OpenID::isFailure($redirect_url))
-
{
-
$this->getRequest()->setError('openid_identifier', 'error');
-
return false;
-
}
-
else
-
{
-
$this->redirect($redirect_url);
-
}
-
}
-
//OpenID2.0
-
else
-
{
-
$form_id = 'openid_message';
-
// trust_rootは認証されるサイトのURL、return_toは認証後にこちらにリダイレクトするURL
-
$form_html = $auth_request->formMarkup(
-
'http://sample.net/',
-
'http://sample.net/openid/finishauth',
-
false,
array('id' =>
$form_id));
-
if (Auth_OpenID::isFailure($form_html))
-
{
-
$this->getRequest()->setError('openid_identifier', 'error');
-
return false;
-
}
-
else
-
{
-
$this->getRequest()->setAttribute('openid_html', $form_html);
-
$this->getRequest()->setAttribute('form_id', $form_id);
-
return true;
-
}
-
}
-
}
-
/*
-
* ログインフォームからPostされたときの処理
-
*/
-
public function executeTryauth()
-
{
-
}
-
public function handleErrorTryauth()
-
{
-
$this->forward('openid', 'login');
-
}
-
/*
-
* Idpからリダイレクトされてからの処理
-
*/
-
public function executeFinishauth()
-
{
-
-
if ($er> E_STRICT) {
-
-
}
-
$store_path = '/tmp/_php_tmp';
-
-
{
-
$this->getRequest()->setError('openid_identifier', 'error');
-
$this->forward('openid', 'index');
-
}
-
$store = new Auth_OpenID_FileStore($store_path);
-
$consumer = new Auth_OpenID_Consumer($store);
-
-
$response = $consumer->complete('http://sample.net/openid/finishauth');
-
if ($response->status == 'cancel')
-
{
-
$this->getRequest()->setError('openid_identifier', 'error');
-
$this->forward('openid', 'index');
-
}
-
else if ($response->status == 'failure')
-
{
-
$this->getRequest()->setError('openid_identifier', 'error');
-
$this->forward('openid', 'index');
-
}
-
else if ($response->status == 'success')
-
{
-
//認証されたopenid
-
$openid = $response->getDisplayIdentifier();
-
//ここに認証処理を書けばよい例えば下記のような感じで。
-
$this->getUser()->setAuthenticated(true);
-
$this->getUser()->addCredential('editor');
-
$this->getUser()->setAttribute('openid', $openid, 'user');
-
-
//どこかにリダイレクトでも
-
$this->redirect('/top/index');
-
}
-
}
-
}