Scope email issue on google login codeigniter

China☆狼群 提交于 2019-12-13 03:39:50

问题


I have created google login using CodeIgniter which is working fine it takes me on login page when I click on Google image after filling up all details when I click on next button then it takes me out from google login to my website and URL look likes

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

which show me 404 error but if I remove &scope=email%20profile%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile from URL then it shows me all information of clients.

controller.

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');
        }
    }
}

view:login.php

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

config/route.php

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

config/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(); 

So, How can I fix this issue? Please help me.

Thank You

来源:https://stackoverflow.com/questions/53300464/scope-email-issue-on-google-login-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!