The Kohana Socialite module provides an expressive, fluent interface to OAuth authentication.
- Download the module into your modules subdirectory.
- Enable the module in your bootstrap file:
/**
* Enable modules. Modules are referenced by a relative or absolute path.
*/
Kohana::modules(array(
// ...
'socialite' => MODPATH.'socialite',
));
- Make sure the settings in
config/socialite.php
are correct for your environment. If not, copy the file toapplication/config/socialite.php
and change the values accordingly.
class Controller_Auth extends Controller
{
public function action_login()
{
$socialite = Socialite::factory()
->driver('Facebook')
->redirect_url(Route::url('auth', array('action' => 'callback',)));
$socialite->redirect();
}
public function action_callback()
{
$socialite = Socialite::factory()
->driver('Facebook')
->redirect_url(Route::url('auth', array('action' => 'callback',)));
try
{
$user = $socialite->user();
}
catch (Socialite_Exception $e)
{
throw new Kohana_Exception($e->getMessage());
}
// Retrieving User Details
$id = $user->get_id();
$nickname = $user->get_nickname();
$first_name = $user->get_first_name();
$surname = $user->get_surname();
$birthday = $user->get_birthday();
$gender = $user->get_gender();
$photo = $user->get_photo();
$email = $user->get_email();
$phone = $user->get_phone();
$website = $user->get_website();
$profile = $user->get_profile();
}
}
- Odnoklassniki
- Vkontakte
The author drew extensive inspiration from the Laravel Socialite package and its related documentation.
This package is open-sourced software licensed under the MIT license