しばらく遊んだ後、自分の質問に答えます。これは私が機能させる方法ですので、必要に応じて変更できます。
注: 私は siteController の代わりに userController を使用しており、それぞれの拡張ページのすべての指示に従ってください。
上記の 2 つのプラグインを使用した場合、それを機能させるために次に行う必要があるのは次のとおりです: (これはステップバイステップのガイドです)
しかし、最も重要なステップは 2c と 3 であり、これらは両方の接着剤です。プラグイン
1) OpenidSelector を使用するログイン ページを用意します。views/user/login.php に配置します
<?php
$this->widget('application.extensions.openidProviders.openidProviders',
array ( 'options' => array ( 'lang' => 'en',
// 'demo' => 'js:true',
'cookie_expires' => 6*30,
)));?>
2) openidSelector からの選択を処理するアクションをセットアップします。これをuserControllerに入れました。
a) メイン構成ファイル内。
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'loginUrl' => array('/user/login'), //change the default login page
),
b) userController ファイルに、ログインおよび認証アクションを追加します。
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('login', 'authenticate'),
アクション #1 actionLogin のコード - これは、ログイン ビュー ページをトリガーするためのものです。
public function actionLogin()
{
// display the login form
$this->render('login',array());
}
c) アクション #2 のコード actionAuthenticate - LOID 命令ページから変更されたコード。これは、ログイン ページで OpenIDProvider が選択されたときに処理するためのものです。
public function actionAuthenticate ()
{
// Put the Simple usage: code on
// http://www.yiiframework.com/extension/loid here:
// Code from loid Simple usage page.
// START HERE
$loid = Yii::app()->loid->load();
if (!empty($_GET['openid_mode'])) {
if ($_GET['openid_mode'] == 'cancel') {
$err = Yii::t('core', 'Authorization cancelled');
} else {
try {
echo $loid->validate() ? 'Logged in.' : 'Failed';
} catch (Exception $e) {
$err = Yii::t('core', $e->getMessage());
}
}
if(!empty($err)) echo $err;
} else {
// **NOTE:Comment out this line from the loid sample page**
// $loid->identity = "http://my.openid.identifier"; //Setting identifier
// this openid_identifier is need after you click the openselector
$loid->identity = $_GET['openid_identifier']; // CHANGE HERE
$loid->required = array('namePerson/friendly', 'contact/email'); //Try to get info from openid provider
$loid->realm = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'];
$loid->returnUrl = $loid->realm . $_SERVER['REQUEST_URI']; //getting return URL
if (empty($err)) {
try {
$url = $loid->authUrl();
$this->redirect($url);
} catch (Exception $e) {
$err = Yii::t('core', $e->getMessage());
}
}
}
// Code from loid Simple usage page.
// END HERE
}
3) openidProviders/views/main-en.php でアクション URL を Authenticate に変更します。
変化する
form action="examples/consumer/try_auth.php" method="get" id="openid_form"
に
form action="authenticate" method="get" id="openid_form"
それだけです。失敗した場合はテストしていません。Google ログインでのみテストしています。