dev-master
9999999-dev https://github.com/lulubin/yii2-oauthAn yii2 extension for oauth
BSD 3-Clause
The Requires
by lulubin
extension oauth yii2
An yii2 extension for oauth
composer require --prefer-dist lulubin/yii2-oauth "dev-master", (*1)
'components' => [ 'authClientCollection' => [ 'class' => 'yii\authclient\Collection', 'clients' => [ 'qq' => [ 'class' => 'lulubin\oauth\Qq', 'clientId' => '***', 'clientSecret' => '***', ], 'weixin' => [ 'class' => 'lulubin\oauth\Weixin', 'clientId' => '***', 'clientSecret' => '***', ], 'weibo' => [ 'class' => 'lulubin\oauth\Weibo', 'clientId' => '***', 'clientSecret' => '***', ], 'github' => [ 'class' => 'yii\authclient\clients\GitHub', 'clientId' => '***', 'clientSecret' => '***, ], ] ] ]
class SiteController extends Controller { public function actions() { return [ 'auth' => [ 'class' => 'yii\authclient\AuthAction', 'successCallback' => [$this, 'successCallback'], ], ]; } public function successCallback($client) { $id = $client->getId(); $attributes = $client->getUserAttributes(); var_dump($id, $attributes); } }
<?php use yii\helpers\Html; use lulubin\oauth\assets\AuthChoiceAsset; AuthChoiceAsset::register($this); ?> <div class="form-group other-way"> <?=Html::a('',['/site/auth','authclient'=>'qq'],['class'=>'qq'])?> <?=Html::a('',['/site/auth','authclient'=>'weibo'],['class'=>'weibo'])?> <?=Html::a('',['/site/auth','authclient'=>'weixin'],['class'=>'weixin'])?> <?=Html::a('',['/site/auth','authclient'=>'github'],['class'=>'github'])?> </div>
(1)QQ互联:http://connect.qq.com/, (*2)
(2)微信开放 平台:https://open.weixin.qq.com/, (*3)
(3)新浪微博开放平台:http://open.weibo.com/, (*4)
(4)Github Developer applications:https://github.com/settings/developers, (*5)
QQ和微博的申请比较麻烦,时间久网站 需要备案;, (*6)
Github的申请则十分迅速,建议先申请这个测试。, (*7)
An yii2 extension for oauth
BSD 3-Clause
extension oauth yii2