HybridAuth continues to issue a User Profile request. Most likely, the user is not connected to the ISP and must authenticate again. "

I am trying to implement HybridAuth for facebook login. but it keeps giving me the above error. I tried to redirect the user to the facebook login page again after this error, but this results in a loop.

Please help me. This is my code.

public function login($provider)
{
    try
    {
        $this->load->model('home_model');
        $this->load->library('HybridAuthLib');
        if ($this->hybridauthlib->providerEnabled($provider))
        {
            $this->service = $this->hybridauthlib->authenticate($provider);
            if ($this->service->isUserConnected())
            {
                $user_profile = $this->service->getUserProfile();  <-- error here
                $access_credentials = $this->service->getAccessToken();
                redirect("site.com/profile/".$user_profile->identifier,"refresh");      
            } else { // Cannot authenticate user
                show_error('Cannot authenticate user');
            }
        }
    }
    catch(Exception $e)
    {
        $error = 'Unexpected error';
        switch($e->getCode())
        {
            case 0 : $error = 'Unspecified error.'; break;
            case 1 : $error = 'Hybriauth configuration error.'; break;
            case 2 : $error = 'Provider not properly configured.'; break;
            case 3 : $error = 'Unknown or disabled provider.'; break;
            case 4 : $error = 'Missing provider application credentials.'; break;
            case 5 : log_message('debug', 'controllers.HAuth.login: Authentification failed. The user has canceled the authentication or the provider refused the connection.');
             //redirect();
            if (isset($service)){
                $service->logout();
            }
            break;
            case 6 : $error = 'User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.';
                     break;
            case 7 : $error = 'User not connected to the provider.';
                     break;
        }


        if (isset($service))
        {
            $service->logout();
        }
        show_error($error);
        /*          redirect("www.facebook.com/dialog/oauth/?
        client_id=[APP_ID]
        &redirect_uri=site.com/hauth/login/Facebook
        &state=1
        &scope=publish_stream
        ","refresh");* <-- when try to use this. It generates a redirect loop from facebook to my site
    }
}

      

+3


source to share





All Articles