Ooguth2 for google登录codeigniter

时间:2014-01-14 09:35:04

标签: php codeigniter oauth-2.0 google-login

我正在尝试使用philsturgeon's OATH2 spark CodeIgniter来验证使用Google的用户。

我安装了Spark并尝试了他在github中提供的用法示例。

class Auth extends CI_Controller {

    public function session($provider) {
        $this->load->helper('url_helper');

        $this->load->spark('oauth2/0.4.0');

        $provider = $this->oauth2->provider($provider, array(
            'id' => 'your-client-id',
            'secret' => 'your-client-secret',
        ));

        if (!$this->input->get('code')) {
            // By sending no options it'll come back here

            echo "Reaching here";

            $provider->authorize();
        } else {
            // Howzit?
            try {
                $token = $provider->access($_GET['code']);

                $user = $provider->get_user_info($token);

                // Here you should use this information to A) look for a user B) help a new user sign up with existing data.
                // If you store it all in a cookie and redirect to a registration page this is crazy-simple.
                echo "<pre>Tokens: ";
                var_dump($token);

                echo "\n\nUser Info: ";
                var_dump($user);
            } catch (OAuth2_Exception $e) {
                show_error('That didnt work: ' . $e);
            }
        }
    }

}

我的登录链接指向http://localhost/educonnect/auth/session/google

根据我的理解,应该把我带到google的登录页面。

但我看到一个回应“到达这里”的页面。我做错了什么?

0 个答案:

没有答案