Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook_ion_auth dont save user after authorization - access_token empty #7

Open
onthefrontline opened this issue Jan 24, 2018 · 1 comment

Comments

@onthefrontline
Copy link

On library Facebook_ion_auth.php, after authorization, access_token comes empty.

In this line:

$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);

I have to add two lines:

$json = json_decode($response, true); //decode response to get access_token
$params['access_token'] = $json['access_token'];

And works.

@vlahx
Copy link

vlahx commented Jun 11, 2019

Maybe that changes helps:

$this->CI->load->config('facebook_ion_auth', TRUE);
        $appid = $this->app_id = $this->CI->config->item('app_id');
		$redir = $this->my_url = $this->CI->config->item('redirect_uri');
        $appsecret = $this->app_secret = $this->CI->config->item('app_secret');
        $scope = $this->scope = $this->CI->config->item('scope');

//////////////////////////////////////////////////////////////////////////////////////////////////////////

$token_url = "https://graph.facebook.com/oauth/access_token?"
                    . "client_id=" . $appid . "&redirect_uri=" . $redir
                    . "&client_secret=" . $appsecret . "&code=" . $code;
                $response = json_decode(file_get_contents($token_url));
                $this->CI->session->set_userdata('access_token', $response->access_token);		
                $graph_url = "https://graph.facebook.com/me?access_token=".$response->access_token . '&fields=name,id,email';

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

$graph_url = "https://graph.facebook.com/me?access_token=".$response->access_token . '&fields=name,id,email,picture';
                $user = json_decode(file_get_contents($graph_url));
                // check if this user is already registered
                if(!$this->CI->ion_auth_model->identity_check($user->email)){
                    $name = explode(" ", $user->name);
                    $register = $this->CI->ion_auth->register($user->name, 'facebookdoesnothavepass123^&*%', $user->email, array('first_name' => $name[0], 'last_name' => $name[1]));
                   $login = $this->CI->ion_auth->login($user->email, 'facebookdoesnothavepass123^&*%', 1);
                } else {
                   $login = $this->CI->ion_auth->login($user->email, 'facebookdoesnothavepass123^&*%', 1);
                }
                return true;

Because $token_url returned with empty fields, i made these changed and use .$response->access_token instead $params['access_token'], of course using json_encode.

For me, its working wonderfull.

@dgeorgiev dgeorgiev assigned dgeorgiev and unassigned dgeorgiev Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants