I am trying to use philsturgeon's OATH2 spark for CodeIgniter to authenticate a user using Google.
I installed the Spark and tried the Usage Example that he gives in the 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);
}
}
}
}
My login link points to http://localhost/educonnect/auth/session/google
As per my understanding, it was supposed to throw me to the login page of google.
But I see a page which echoes "Reaching here". What am I doing wrong?