Skip to content

Latest commit

 

History

History
88 lines (71 loc) · 2.43 KB

README.md

File metadata and controls

88 lines (71 loc) · 2.43 KB

Yii Authclient for Weibo,QQ,Wechat and etc.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist changyuan/yii2-authclient

or add

"changyuan/yii2-authclient": "~2.1.0"

to the require section of your composer.json.

Usage

'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
]

in view

 //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(); ?>

参考

Q&A

Q: this error "Invalid auth state parameter." ?

A: remove sub class $this->removeState('authState');