当我尝试在Yii2中使用社交媒体登录时,如果谷歌,脸书,推特和GitHub错误。我确信我在\ basic_yii2 \ config \ web.php上的配置是正确的。这是我的配置:
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\Google',
'clientId' => 'example',
'clientSecret' => 'example',
],
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'clientId' => 'example',
'clientSecret' => 'example',
],
'twitter' => [
'class' => 'yii\authclient\clients\Twitter',
'consumerKey' => 'example',
'consumerSecret' => 'example',
],
'github' => [
'class' => 'yii\authclient\clients\Github',
'clientId' => 'example',
'clientSecret' => 'example',
],
],
],
这是我对\ basic_yii2 \ controllers \ siteConttroler.php的配置:
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV ? 'testme' : null,
],
'auth' => [
'class' => 'yii\authclient\AuthAction',
'successCallBack' => [$this, 'successCallBack'],
],
];
}
public function successCallBack($client)
{
// get user data from client
$userAttributes = $client->getUserAttributes();
print_r($userAttributes);
exit;
}
答案 0 :(得分:0)
属性名称为successCallback
而不是successCallBack
:
'auth' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'successCallBack'],
],