rhosocial / yii2-oauth2client
Rho 社交 OAuth 2 客户端,适用于 Yii 2 网络应用。
dev-master
2015-09-20 05:04 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: *
- yiisoft/yii2-authclient: *
This package is auto-updated.
Last update: 2024-09-08 06:37:21 UTC
README
Rho 社交 OAuth 2 客户端,适用于 Yii 2 网络应用。此扩展目前处于开发中。如果您没有获得测试邀请,请勿下载、分支或使用此扩展,我们暂时不接受拉取请求。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令
php composer.phar require --prefer-dist rhosocial/yii2-oauth2client "*"
或者将以下内容添加到你的 composer.json
文件的 require 部分。
"rhosocial/yii2-oauth2client": "*"
使用方法
将 Auth 动作附加到控制器
class SiteController extends Controller { public function actions() { return [ 'auth' => [ 'class' => 'rhosocial\Oauth2Client\AuthAction', 'successCallback' => [$this, 'onAuthSuccess'], ], ] } public function onAuthSuccess($client) { $attributes = $client->getUserAttributes(); // user login or signup comes here } }
将以下代码附加到主配置的 Component
部分
'authClientCollection' => [ 'class' => 'yii\authclient\Collection', 'clients' => [ 'rho_social' => [ 'class' => 'rhosocial\Oauth2client\Oauth2client', 'clientId' => <client id>, 'clientSecret' => <client secret>, ], ], ],
请将 <client id>
和 <client secret>
替换为您分配的值。
然后在登录视图中使用 AuthChoice 小部件,将以下代码插入到您希望的位置
<?= yii\authclient\widgets\AuthChoice::widget([ 'baseAuthUrl' => ['site/auth'], 'popupMode' => true, ]);?>
如果您没有选择 'site/auth' 作为您的 Auth 动作,请修改 'baseAuthUrl' 属性为实际的路径。
联系我们
如果您对 yii2-oauth2client 有任何问题或好的想法,请在那里讨论,或者发送电子邮件到 opensource@dev.rho.social。谢谢!
如果您想发送电子邮件报告问题,请先简要介绍自己,例如包括您的头衔和 github 主页。