Using Laravel 4.2+ with hybridauth package.

Follow the steps:

1) Start by editing composer.json and specifying that you need the latest version (denoted by *) of the HybridAuth package (hybridauth/hybridauth). By default Composer will search for the package in the Packagist repository:

{
	...
	"require": {
		...
		"hybridauth/hybridauth": "*"
	},
	...
}

2) Now run php composer.phar update (or composer update, depending on how your system is configured) to fetch and install the package.

3) Create a HybridAuth configuration file (app/config/hybridauth.php) and specify your social networks’ credentials:

you can get these ID and secret from app console of respective services.

<?php
return array(	
	"base_url"   => "http://URL/social/auth",
	"providers"  => array (
		"Google"     => array (
			"enabled"    => true,
			"keys"       => array ( "id" => "ID", "secret" => "SECRET" ),
			),
		"Facebook"   => array (
			"enabled"    => true,
			"keys"       => array ( "id" => "ID", "secret" => "SECRET" ),
			),
		"Twitter"    => array (
			"enabled"    => true,
			"keys"       => array ( "key" => "ID", "secret" => "SECRET" )
			)
	),
);

4) Edit your application’s Routes file (app/routes.php) with the following code:

This code can be easily ported to controller for keeping the route file clean.

Route::get('social/{action?}', array("as" => "hybridauth", function($action = "")
{
	// check URL segment
	if ($action == "auth") {
		// process authentication
		try {
			Hybrid_Endpoint::process();
		}
		catch (Exception $e) {
			// redirect back to http://URL/social/
			return Redirect::route('hybridauth');
		}
		return;
	}
	try {
		// create a HybridAuth object
		$socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
		// authenticate with Google
		$provider = $socialAuth->authenticate("google");
		// fetch user profile
		$userProfile = $provider->getUserProfile();
	}
	catch(Exception $e) {
		// exception codes can be found on HybBridAuth's web site
		return $e->getMessage();
	}
	// access user profile data or do database stuff 
	echo "Connected with: <b>{$provider->id}</b><br />";
	echo "As: <b>{$userProfile->displayName}</b><br />";
	echo "<pre>" . print_r( $userProfile, true ) . "</pre><br />";

	// logout
	$provider->logout();
}));

That’s  it. Just a few lines of code get you a social network authentication module up and running at http://URL/social/.

I do suggest that you move all logic to Controller/Model and keep your Routes clean.

 

ref.: laravel4-package-management-with-composer