PHP code example of yuyangame / yii2-oauth
1. Go to this page and download the library: Download yuyangame/yii2-oauth library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yuyangame / yii2-oauth example snippets
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'qq' => [
'class' => 'yuyangame\oauth\QqAuth',
'clientId' => 'YOUR_OPEN_APPID',
'clientSecret' => 'YOUR_OPEN_APPSCRET',
],
'weibo' => [
'class' => 'yuyangame\oauth\WeiboAuth',
'clientId' => 'YOUR_OPEN_APPID',
'clientSecret' => 'YOUR_OPEN_APPSCRET',
],
'weixin' => [
'class' => 'yuyangame\oauth\WeixinAuth',
'clientId' => 'YOUR_OPEN_APPID',
'clientSecret' => 'YOUR_OPEN_APPSCRET',
],
]
]
...
]
class SiteController extends Controller
{
public function actions()
{
return [
'auth' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'successCallback'],
],
];
}
/**
* Success Callback
* @param QqAuth|WeiboAuth $client
* @see http://wiki.connect.qq.com/get_user_info
* @see http://stuff.cebe.cc/yii2docs/yii-authclient-authaction.html
*/
public function successCallback($client) {
$id = $client->getId(); // qq | weibo | weixin
$attributes = $client->getUserAttributes(); // basic info
$userInfo = $client->getUserInfo(); // user extend info
// login or signup
}
}
<?=
yii\authclient\widgets\AuthChoice::widget([
'baseAuthUrl' => ['site/auth'],
//'popupMode' => false,
])
php composer.phar