简体   繁体   English

Yii2 AuthClient Facebook

[英]Yii2 AuthClient Facebook

I have a problem with FB login in my Yii application. 我的Yii应用程序中FB登录存在问题。 When I try to get the user attributes, application returns internal server error. 当我尝试获取用户属性时,应用程序返回内部服务器错误。 I checked all logs and found nothing. 我检查了所有日志,却一无所获。

This is my config 这是我的配置

'authClientCollection' => [
        'class' => 'yii\authclient\Collection',
        'clients' => [
            'facebook' => [
                'class' => 'yii\authclient\clients\Facebook',
                'authUrl' => 'https://www.facebook.com/dialog/oauth?display=popup',
                'clientId' => 'xxxxxxxx',
                'clientSecret' => 'xxxxxxxxx',
            ],
        ],
    ],

Controller actions 控制器动作

public function actions()
{
    return
    [
        'auth' =>
        [
            'class' => 'yii\authclient\AuthAction',
            'successCallback' => [$this, 'authSuccess'],
        ],
    ];
}

and the app crashes when it reaches this statement inside the callback 当应用在回调内到达此语句时,应用崩溃

$attributes = $client->getUserAttributes();

this is the $client object 这是$ client对象

    object(yii\authclient\clients\Facebook)#115 (20) {
  ["authUrl"]=>
  string(51) "https://www.facebook.com/dialog/oauth?display=popup"
  ["tokenUrl"]=>
  string(45) "https://graph.facebook.com/oauth/access_token"
  ["apiBaseUrl"]=>
  string(26) "https://graph.facebook.com"
  ["scope"]=>
  string(5) "email"
  ["attributeNames"]=>
  array(2) {
    [0]=>
    string(4) "name"
    [1]=>
    string(5) "email"
  }
  ["version"]=>
  string(3) "2.0"
  ["clientId"]=>
  string(15) "xxxxxxxxxx"
  ["clientSecret"]=>
  string(32) "xxxxxxxxxx"
  ["_returnUrl":"yii\authclient\BaseOAuth":private]=>
  string(49) "http://xxxxxx.xx/auth?authclient=facebook"
  ["_curlOptions":"yii\authclient\BaseOAuth":private]=>
  array(0) {
  }
  ["_accessToken":"yii\authclient\BaseOAuth":private]=>
  object(yii\authclient\OAuthToken)#117 (5) {
    ["tokenParamKey"]=>
    string(12) "access_token"
    ["tokenSecretParamKey"]=>
    string(18) "oauth_token_secret"
    ["createTimestamp"]=>
    int(1461360063)
    ["_expireDurationParamKey":"yii\authclient\OAuthToken":private]=>
    NULL
    ["_params":"yii\authclient\OAuthToken":private]=>
    array(2) {
      ["access_token"]=>
      string(175) "EAACZCvJlBssYBAF1vwxq7PMgKAsEz5GueWEpBTf3OZAGEHPrONRKVXLGggRudgsNcpHiWD2IWDlEwnVmku9qmyYvUWh2VYVPShOK6VfsQ7TID1dEozVUMgYU01raFK3IBJ2mvi5PNztnqgQ12d0yBZBYnZCVloft4FmkkYyjvwZDZD"
      ["expires"]=>
      string(7) "5181417"
    }
  }
  ["_signatureMethod":"yii\authclient\BaseOAuth":private]=>
  array(0) {
  }
  ["_id":"yii\authclient\BaseClient":private]=>
  string(8) "facebook"
  ["_name":"yii\authclient\BaseClient":private]=>
  NULL
  ["_title":"yii\authclient\BaseClient":private]=>
  NULL
  ["_userAttributes":"yii\authclient\BaseClient":private]=>
  NULL
  ["_normalizeUserAttributeMap":"yii\authclient\BaseClient":private]=>
  NULL
  ["_viewOptions":"yii\authclient\BaseClient":private]=>
  NULL
  ["_events":"yii\base\Component":private]=>
  array(0) {
  }
  ["_behaviors":"yii\base\Component":private]=>
  NULL
}

EDIT: I just found out that it must be some problem with Yii's AuthClient (maybe FB changed response?), because I used this in another project, about a year ago and it worked just fine. 编辑:我刚刚发现Yii的AuthClient一定有问题(也许FB更改了响应?),因为大约一年前,我在另一个项目中使用了它,并且效果很好。 Now i tried to login to that project and it does the same thing 现在我尝试登录到该项目,它执行相同的操作

sorry, I haven't qualification for comment... please post your function content 抱歉,我没有发表评论的资格...请发布您的功能内容

function authSuccess($client) {
...
}

extra: check your user model has implements IdentityInterface and yii\\web\\User it's set user attribute at login function. 另外:检查您的用户模型是否实现了IdentityInterface和yii \\ web \\ User,这是在登录功能时设置的用户属性。 you could set breakpoint on there. 您可以在此处设置断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM