我的Yii应用程序中的FB登录有问题。当我尝试获取用户属性时,应用程序返回内部服务器错误。我检查了所有日志,什么也没找到。
这是我的配置
'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',
],
],
],
控制器操作
public function actions()
{
return
[
'auth' =>
[
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'authSuccess'],
],
];
}
并且应用程序在回调中到达此语句时崩溃
$attributes = $client->getUserAttributes();
这是$ 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
}
编辑:我刚刚发现Yii的AuthClient一定有问题(可能是FB更改了响应?),因为我在大约一年前的另一个项目中使用过它它运作得很好。现在我尝试登录到该项目并执行相同的操作
答案 0 :(得分:0)
function authSuccess($client) {
...
}
额外: 检查您的用户模型是否实现了IdentityInterface和yii \ web \ User它在登录功能时设置了用户属性。 你可以在那里设置断点。