poofe / yii2-cas-client
为 Yii2 的 CAS 身份验证
1.0.0
2018-07-25 03:24 UTC
Requires
- php: >=5.4.0
- jasig/phpcas: ^1.3
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2024-09-29 06:41:10 UTC
README
使用 phpCAS 库进行 CAS 身份验证的 Yii2 库。
用法
-
使用
composer require poofe/yii2casclient
命令将此添加到项目中 -
配置 Yii2 应用程序,例如在
backend/config/main.php
文件中return [ ... 'session' => [ 'class' => 'poofe\yii2casclient\cas\Session', ... ], 'modules' => [ 'cas' => [ 'class' => 'poofe\yii2casclient\cas\CasModule', 'config' => [ 'host' => 'ssoserver.example.com', 'port' => '443', 'path' => '/idp/profile/cas', // optional parameters 'certfile' => false, // empty, or path to a SSL cert, or false to ignore certs 'debug' => true, // will add many logs into X/runtime/logs/cas.log ], ],
-
在
SiteController
中添加使用此 CAS 模块的 action,例如public function actionLogin() { if (!Yii::$app->user->isGuest) { return $this->goHome(); } return $this->redirect(['/cas/auth/login']); } public function actionLogout() { if (Yii::$app->user->isGuest) { return $this->redirect(['/cas/auth/logout']); } return $this->goHome(); }
注意
实现 yii\web\IdentityInterface
的 user
组件将在查询 CAS 服务器后获取本地配置。这意味着,如果 User
是应用程序组件并且 CAS 返回的用户名为 "bibendum",则只有当 User::findIdentity("bibendum")
的结果不为空时,认证才会成功。
动作路径 '/cas/auth/login' 以应用程序配置中定义的模块别名开始,例如在 'modules' => [ 'cas' => [ ... ] ]
中定义的 'cas'
。