长原 / yii2-authclient
适用于QQ、微博、微信的yii2-authclient
1.0.1
2017-09-21 06:17 UTC
Requires
- yiisoft/yii2-authclient: ~2.1.0
This package is auto-updated.
Last update: 2024-09-26 19:19:49 UTC
README
安装
安装此扩展的首选方式是通过composer。
运行以下命令之一:
composer require --prefer-dist changyuan/yii2-authclient
或者
"changyuan/yii2-authclient": "~2.1.0"
将以下内容添加到您的composer.json文件中的require
部分。
使用方法
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'weibo' => [
'class' => 'changyuan\authclient\clients\Weibo',
'clientId' => 'wb_key',
'clientSecret' => 'wb_secret',
],
'qq' => [
'class' => 'changyuan\authclient\clients\QQ',
'clientId' => 'qq_appid',
'clientSecret' => 'qq_appkey',
],
'wechat' => [
'class' => 'changyuan\authclient\clients\Wechat',
'clientId' => 'weixin_appid',
'clientSecret' => 'weixin_appkey',
],
'wechatmp' => [
'class' => 'changyuan\authclient\clients\Wechat',
'type' => 'mp',
'clientId' => 'weixin_appid',
'clientSecret' => 'weixin_appkey',
],
],
]
// other components
]
在视图中
//The first way in view:
<?= yii\authclient\widgets\AuthChoice::widget([
'baseAuthUrl' => ['site/auth']
]); ?>
//The second way in view:
<?php
use yii\authclient\widgets\AuthChoice;
?>
<?php $authAuthChoice = AuthChoice::begin([
'baseAuthUrl' => ['site/auth']
]); ?>
<ul>
<?php foreach ($authAuthChoice->getClients() as $client): ?>
<li><?= $authAuthChoice->clientLink($client) ?></li>
<?php endforeach; ?>
</ul>
<?php AuthChoice::end(); ?>
问答
问:这个错误 "Invalid auth state parameter." 是什么意思?
答:移除子类中的代码 $this->removeState('authState');