在谷歌登录笨范围的电子邮件问题(Scope email issue on google login

2019-10-30 12:27发布

我一直在使用这笨工作正常需要我的登录页面,当我点击创建谷歌登录Google image填满所有细节后,当我点击下一步按钮,然后它需要我从谷歌登陆我的网站和网址喜欢看

https://example.com/google_login?code=4/lQDGQ6sJog3ZrLKGJtn-VVD3rbzgJl16jMLUrk6wzBIbsu-F6mjlLuPOepeobDLmFYqQL25jo4iAgI9ZnVKTSVY&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile

这给我404错误,但如果我删除&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile从URL则显示我的客户的所有信息。

控制器。

public function login()
{
    $userData = array();
    if($this->facebook->is_authenticated()){
        $fbUserProfile = $this->facebook->request('get', '/me?fields=id,first_name,last_name,email,picture');
        $userData['oauth_provider'] = 'facebook';
        $userData['oauth_uid'] = $fbUserProfile['id'];
        $userData['name'] = $fbUserProfile['first_name']." ".$fbUserProfile['last_name'];
        $userData['email'] = $fbUserProfile['email'];
        $userData['user_image'] = $fbUserProfile['picture']['data']['url'];
        $userID = $this->user->checkUser($userData);
        if(!empty($userID))
        {
            $data['userData'] = $userData;
            $this->session->set_userdata('userData',$userData);
        }
        else
        {
           $data['userData'] = array();
        }
        $data['logoutURL'] = $this->facebook->logout_url();
    }
    else
    {
        $data['authURL'] =  $this->facebook->login_url();
    }
    $data['loginURL'] = $this->google->loginURL();
    $this->load->view('login',$data);
}

public function google_login()
{
    if($this->session->userdata('loggedIn') == true){
        redirect('profile');
    }
    if(isset($_GET['code'])){
        if($this->google->getAuthenticate()){
            $gpInfo = $this->google->getUserInfo();
            $userData['oauth_provider'] = 'google';
            $userData['oauth_uid']         = $gpInfo['id'];
            $userData['name']     = $gpInfo['given_name'].' '.$gpInfo['family_name'];
            $userData['email']             = $gpInfo['email'];
            $userData['user_image']         = !empty($gpInfo['picture'])?$gpInfo['picture']:'';
            $userID = $this->Google_user->checkUser($userData);
            $this->session->set_userdata('loggedIn', true);
            $this->session->set_userdata('userData', $userData);
            redirect('profile');
        }
    }
}

观点:login.php中

<a href="<?php echo $loginURL; ?>" class="google btn-block"><i class="fa fa-google-plus"></i></a>

配置/ route.php

$route['google_login'] = "welcome/google_login";

配置/ google.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');
$config['google']['client_id']        = '**********************************************';
$config['google']['client_secret']    = '************************';
$config['google']['redirect_uri']     = 'https://example.com/google_login';
$config['google']['application_name'] = 'Login to Example';
$config['google']['api_key']          = '';
$config['google']['scopes']           = array(); 

所以,我怎样才能解决这个问题? 请帮我。

谢谢

文章来源: Scope email issue on google login codeigniter