Using Laravel Socialite to login to facebook
In your composer.json add- "laravel/socialite": "~2.0",
"require": {
"laravel/framework": "5.0.*",
"laravel/socialite": "~2.0",
the run composer update
In config/services.php add:
//Socialite
'facebook' => [
'client_id' => '1234567890444',
'client_secret' => '1aa2af333336fffvvvffffvff',
'redirect' => 'http://laravel.dev/login/callback/facebook',
],
You need to create two routes, mine are like these:
//Social Login
Route::get('/login/{provider?}',[
'uses' => 'AuthController@getSocialAuth',
'as' => 'auth.getSocialAuth'
]);
Route::get('/login/callback/{provider?}',[
'uses' => 'AuthController@getSocialAuthCallback',
'as' => 'auth.getSocialAuthCallback'
]);
You also need to create controller for the routes above like so:
<?php namespace App\Http\Controllers;
use Laravel\Socialite\Contracts\Factory as Socialite;
class AuthController extends Controller
{
public function __construct(Socialite $socialite){
$this->socialite = $socialite;
}
public function getSocialAuth($provider=null)
{
if(!config("services.$provider")) abort('404'); //just to handle providers that doesn't exist
return $this->socialite->with($provider)->redirect();
}
public function getSocialAuthCallback($provider=null)
{
if($user = $this->socialite->with($provider)->user()){
dd($user);
}else{
return 'something went wrong';
}
}
}
and finally add Site URL to your Facebook App like so:
laravel Socialite facebook login
Hi you are missing to give credentials of social media put that in config/services.php
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('CALLBACK_URL_FACEBOOK'),
]
And run the following commands :
php artisan clear-compiled
composer dump-autoload
php artisan optimize
Related Topics
How to Use MySQLi_Query() in PHP
How to Setup Docker + PHPstorm + Xdebug on Ubuntu 16.04
Check for Duplicates Before Inserting
How to Take a Photo and Send to Http Post Request with Android
How to Send Multiple Attachment in Single Mail in PHP
Apple Sign in "Invalid_Client", Signing Jwt for Authentication Using PHP and Openssl
Php: How to Capture Browser Window Screen with PHP
Sort Xml via Attribute Value PHP
PHP - Replace Colour Within Image
Send Emails with International Accent and Special Characters
Can Anyone Get Access to My PHP Source Code
Create Thumbnail from Video Without Ffmpeg in PHP
Allow User Submitted HTML in PHP
Getting the Full Url Including the Query String After Hash