Alo*_*cus 22 openid openid-selector yii lightopenid
我想在Yii中使用OpenID支持.
在研究了可能的插件之后,我找到了这两个插件.一个用于OpenidSelector,另一个用于LightOpenId
http://www.yiiframework.com/extension/simpleopenidselector/
http://www.yiiframework.com/extension/loid
这些是在Yii中用于OpenId支持的正确扩展吗?还要别的吗?如果这些扩展是正确的,我想了解如何处理这些扩展.
这是我认为我需要按照页面上的说明安装它们.
然后我有点迷失,因为我不理解Loid中的Usage样本,我不知道如何做(1)和(3).
如果我走在正确的轨道上并且可能提供一些指导,请告诉我.谢谢.
Alo*_*cus 10
玩了一段时间之后,我将回答我自己的问题.这就是我的工作方式,因此您可以根据自己的需要进行更改.
注意:我使用userController而不是siteController,请按照相应扩展页面中的所有说明进行操作.
如果您使用了上面所示的两个插件,那么接下来需要做的是:(这是一步一步的指导) 但最重要的步骤是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,
)));?>
Run Code Online (Sandbox Code Playgroud)
2)设置动作以处理来自openidSelector的选择.我把它放在userController中.
a)在主配置文件中.
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'loginUrl' => array('/user/login'), //change the default login page
),
Run Code Online (Sandbox Code Playgroud)
b)在userController文件中,添加登录和验证操作
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('login', 'authenticate'),
Run Code Online (Sandbox Code Playgroud)
操作代码#1 actionLogin - 这是触发登录视图页面.
public function actionLogin()
{
// display the login form
$this->render('login',array());
}
Run Code Online (Sandbox Code Playgroud)
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
}
Run Code Online (Sandbox Code Playgroud)
3)在openidProviders/views/main-en.php中将操作URL更改为Authenticate
更改
form action="examples/consumer/try_auth.php" method="get" id="openid_form"
Run Code Online (Sandbox Code Playgroud)
至
form action="authenticate" method="get" id="openid_form"
Run Code Online (Sandbox Code Playgroud)
那应该是它.没有测试过失败的情况,只测试了google登录.