如何解决OpenId支持Yii
| 我想在Yii中使用OpenID支持。 在研究了可能的插件之后,我找到了这两个。一个用于OpenidSelector,另一个用于LightOpenId http://www.yiiframework.com/extension/simpleopenidselector/ http://www.yiiframework.com/extension/loid 这些是在Yii中用于OpenId支持的正确扩展吗?还要别的吗? 如果这些扩展正确,我想获得一些指导。 除了按照页面上的说明安装它们之外,我还需要执行此操作。 创建OpenIdUserIdentity扩展CUserIdentity并在其中放置authenticate()代码 创建一个登录页面,然后在视图中放置simpleopenidselector代码。 在siteController中创建一个actionOpenIdLogin方法 然后我有点迷茫,因为我不了解Loid中的“用法”示例,而且我不确定如何执行上述(1)和(3)。 如果我走的路正确,请告诉我,并可能提供一些指导。谢谢。解决方法
在玩了一段时间之后,我将回答我自己的问题。这就是我的工作方式,因此您可以根据需要进行更改。
注意:我使用的是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,)));?>
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登录名进行了测试。
,现在有YiiAuth,它使用HybridAuth库。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。