changyuan/yii2-authclient

yii2-authclient for qq weibo wechat

Installs: 109

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 3

Forks: 0

Open Issues: 0

Type:composer-pllugin

1.0.1 2017-09-21 06:17 UTC

This package is auto-updated.

Last update: 2024-04-26 18:27:44 UTC


README

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');