How login with Facebook and Google without authentication in Laravel 5.1 using socialite version 2.1?
‘facebook’ => [‘client_id’ => ‘id’,
‘client_secret’ =>
‘fgdfgsdfgrtt45453’,
‘redirect’ => ‘http://example.com/callback‘,
],
In route.php
Route::get(‘/redirect’, ‘SocialAuthFacebookController@redirect’);
Route::get(‘/callback’, ‘SocialAuthFacebookController@callback’);
And I have add Services/SocialFacebookAccountService.php directory in App.
SocialFacebookAccountService.php
namespace AppServices;
use AppSocialFacebookAccount;
use AppUser;
use LaravelSocialiteContractsUser as ProviderUser;
class SocialFacebookAccountService
{
public function createOrGetUser(ProviderUser $providerUser)
{
$account = SocialFacebookAccount::whereProvider('facebook')
->whereProviderUserId($providerUser->getId())
->first();
echo 'Account info : ';
if ($account) {
return $account->user;
} else {
$account = new SocialFacebookAccount([
'provider_user_id' => $providerUser->getId(),
'provider' => 'facebook'
]);
$user = User::whereEmail($providerUser->getEmail())->first();
if (!$user) {
$user = User::create([
'email' => $providerUser->getEmail(),
'name' => $providerUser->getName(),
'password' => md5(rand(1,10000)),
]);
}
$account->user()->associate($user);
$account->save();
return $user;
}
}
}
Please help , How to get user info in callback.
from Laravel Questions and Answers https://laravelquestions.com/php/how-login-with-facebook-and-google-without-authentication-in-laravel-5-1-using-socialite-version-2-1/
via Lzo Media
Great article it will be informative for me i would like to use here this crucial tips hire php developer
ReplyDelete