Yii2 получает атрибуты пользователя из входа в систему Google authclient

Я использую логин Google authclient в своем приложении. Логин Google работает отлично, но я не могу получить атрибуты пользователя.
web.php

 'google' => [
            'class' => 'yii\authclient\clients\GoogleOAuth',
            'clientId' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
            'clientSecret' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
            'scope'=>' https://www.googleapis.com/auth/plus.profile.emails.read',
            'returnUrl'=>'https://localhost/mysite',
        ],    

sitecontroller.php

 public function actions()
{
    return [

        'auth' => [
            'class' =>'yii\authclient\AuthAction',
            'successCallback' => [
            $this, 'successCallback'
            ],
        ],
    ];
}  

успешный обратный вызов()

public function successCallback($client)
{

    $attributes = $client->getUserAttributes();
    // print_r($attributes);die();
    // user login or signup comes here
   // print_r($attributes['email']);die();
    $user_email = $attributes['email'];
    $user_name = $attributes['name'];
    // echo $user_email;echo '<br>';
    // echo $user_name;
    // die();

    $user = User::find()->where(['user_email'=>$user_email])->one();
    $count = count($user);
    if ($count == 0 ){
        return $this->redirect(['user/create?email='.$user_email.'&name='.$user_name.'']);
    }else{
        return Yii::$app->user->login($user);
        //echo Yii::$app->user->identity->id;die();
    }  

Может ли кто-нибудь помочь мне в этом..
Спасибо..


person Mohammed Iqbal Khan    schedule 09.12.2015    source источник


Ответы (1)


установите свой returnUrl в web.php следующим образом: https://test.com/site/auth?authclient=google

ваш код должен быть таким, как показано ниже:

 'google' => [
        'class' => 'yii\authclient\clients\Google',
        'clientId' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'clientSecret' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
        'returnUrl'=>'https://test.com/site/auth?authclient=google',
    ], 
person ali abdzad    schedule 01.11.2016
comment
Хотя этот фрагмент кода может решить проблему, включение объяснения действительно помогает улучшить качество вашего сообщения. Помните, что вы отвечаете на вопрос читателей в будущем, а не только того, кто задает сейчас! Пожалуйста, отредактируйте свой ответ, чтобы добавить объяснение и указать, какие ограничения и предположения применяются. - person Toby Speight; 01.11.2016