Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter Hybridauth-此页面的授权状态[state=HA-SOME_state_DATA]无效或已被使用_Codeigniter_Oauth 2.0_Codeigniter 3_Hybridauth - Fatal编程技术网

Codeigniter Hybridauth-此页面的授权状态[state=HA-SOME_state_DATA]无效或已被使用

Codeigniter Hybridauth-此页面的授权状态[state=HA-SOME_state_DATA]无效或已被使用,codeigniter,oauth-2.0,codeigniter-3,hybridauth,Codeigniter,Oauth 2.0,Codeigniter 3,Hybridauth,我正在使用Hybridauth和Codeigniter在我的应用程序中实现社交登录按钮。我只需要谷歌、Facebook和LinkedIn的社交登录按钮。我已经成功地实现了Google注册和注册方法,但同样的代码不适用于Facebook和LinkedIn,下面是我经常遇到的错误,这个例外 行动,我们遇到了问题!授权状态 本页的[state=HA-RBNC6FHJ54VZAM1KTD7EI3SPYG08U2OLWQ9X]为 无效或已被使用。无法获取您的数据!追求 有一段时间 我的hybriduath

我正在使用Hybridauth和Codeigniter在我的应用程序中实现社交登录按钮。我只需要谷歌、Facebook和LinkedIn的社交登录按钮。我已经成功地实现了Google注册和注册方法,但同样的代码不适用于Facebook和LinkedIn,下面是我经常遇到的错误,这个例外

行动,我们遇到了问题!授权状态 本页的[state=HA-RBNC6FHJ54VZAM1KTD7EI3SPYG08U2OLWQ9X]为 无效或已被使用。无法获取您的数据!追求 有一段时间

我的hybriduath配置文件。

<?php

$config['hybridauth'] = [
    //Location where to redirect users once they authenticate with a provider
    'callback' => 'http://localhost/insurance-experts/auth/social_auth',

    //Providers specifics
    'providers' => [
        'Google'   => [
            'enabled' => true,
            'keys' => [
                'id'  => '...',
                'secret' => '...',
            ],
            'debug_mode' => true,
            'debug_file' => APPPATH . 'logs/' . date('Y-m-d') . '.log',

        ], //To populate in a similar way to Twitter
        'Facebook' => [
            'enabled' => true,
            'keys' => [
                'id'  => '...',
                'secret' => '...'
            ],
            'debug_mode' => true,
            'debug_file' => APPPATH . 'logs/' . date('Y-m-d') . '.log',
        ],
        'LinkedIn' => [
            'enabled' => true,
            'keys' => [
                'id'  => '...',
                'secret' => '...'
            ],
            'debug_mode' => true,
            'debug_file' => APPPATH . 'logs/' . date('Y-m-d') . '.log',
        ],
    ]
];
Codeigniter版本:3.x

Hybridauth版本:3

我想知道这行代码是否不是问题的根源:
$adapter->disconnect()尝试删除它。@pixeline那么它肯定会导致所有三个都出现错误,但Google auth工作正常。。更不用说我切换了库,因为我读到它不再被维护了。
public function social_auth()
    {
        $user_profile = NULL;

        $auth_provider = $this->input->get('auth_provider');

        // Check if it is redirected url with code & state params
        if (!isset($_GET['code'])) {
            $user_role = $this->input->get('role');
            // Save it in the session to reuse it after auth redirect
            // We'll need it in case user does not exist
            $_SESSION['temp_user_role'] = $user_role;
        }

        switch ($auth_provider) {
            case GOOGLE:
                $auth_provider = GOOGLE;
                break;

            case FACEBOOK:
                $auth_provider = FACEBOOK;
                break;

            case LINKEDIN:
                $auth_provider = LINKEDIN;
                break;

            default:
                $auth_provider = GOOGLE;
                break;
        }

        // Load the hybridauth config file
        $this->config->load('hybridauth');

        //First step is to build a configuration array to pass to `Hybridauth\Hybridauth`
        $config = $this->config->item('hybridauth');

        try {
            //Feed configuration array to Hybridauth
            $hybridauth = new Hybridauth($config);

            //Attempt to authenticate users with a provider by name
            $adapter = $hybridauth->authenticate($auth_provider);

            //Retrieve the user's profile
            $user_profile = $adapter->getUserProfile();

            //Disconnect the adapter 
            $adapter->disconnect();
        } catch (\Exception $e) {
            echo 'Oops, we ran into an issue! ' . $e->getMessage();
        }

        if (!empty($user_profile)) {

            $email = $user_profile->email;

            // Check if email exist in DB then sign in the user
            $user_data = $this->User_model->find(['email' => $email], USERS);

            if (!empty($user_data) && count($user_data) > 0) {
                $user = $user_data[0];

                $user_role = "";

                // Cross check the user role 
                $user_groups = $this->ion_auth->get_users_groups($user->id)->result();

                if (!empty($user_groups)) {
                    $group = $user_groups[0];

                    switch ($group->id) {
                        case ROLE_INDIVIDUAL:
                            $user_role = ROLE_INDIVIDUAL_STRING;
                            break;

                        case ROLE_COMPANY:
                            $user_role = ROLE_COMPANY_STRING;
                            break;
                    }
                } else {
                    // Something went wrong, Force logout user
                    redirect('auth/logout');
                }

                if (empty($user_role)) {
                    redirect('auth/logout');
                }

                // Explicitly set the user role here
                // coz it required in header's menubar
                $user->role = $user_role;

                $login_done = $this->ion_auth->set_session($user);

                if ($login_done == TRUE) {
                    // Everything is OK, redirect the user to home page
                    redirect('/');
                } else {
                    echo "We could not logged you in this moment!Please try after some time.";
                }
            } else {

                $this->create_user_via_social_sign_up($user_profile);
            }
        } else {
            echo "Unable to get your data!Try after some time.";
        }
    }

    private function create_user_via_social_sign_up($user_profile)
    {
        $user_role = check_group($_SESSION['temp_user_role']);

        if (empty($user_profile) or empty($user_role)) {
            // Something went wrong, Force logout user
            redirect('auth/logout');
        }

        $email = $user_profile->email;
        // Generate a random password, 
        $password = substr(md5(rand()), 0, 7);

        $extra_data = [
            'active' => 1,
            'is_approved' => 1
        ];

        $this->db->trans_start();

        // Directly register user via Model method as no need to send the activation email
        $id = $this->ion_auth_model->register($email, $password, $email, $extra_data, [$user_role]);

        $user_data = $this->User_model->find(['id' => $id], USERS);

        $user = $user_data[0];

        // Add the role in user object
        $user->role = $user_role;

        $redirectProfileUrl = base_url('Profile_setting/');

        if ($this->ion_auth->set_session($user)) {

            // Create empty records in tables
            $this->User_model->create_user_entries($user->id, $user_role);

            if ($this->db->trans_status() !== false) {
                $this->db->trans_commit();
                redirect($redirectProfileUrl);
            } else {
                // Something went wrong rollback all the transactions & inform the user
                $this->db->trans_rollback();
                echo "Our system is down right now!Please try after some time.";
            }
        }
    }