Laravel 5 socialize facebook login

4k Views Asked by At

I use auth login (out of the box). I have want to add Facebook login. I have installed Socialize package, and In Auth/AuthController I added method fb:

public function fb()
    {
        return \Socialize::with('facebook')->redirect();
    }

When I call http://ip/auth/fb its redirect me to http://ip/auth/login#=

Please help

2

There are 2 best solutions below

0
On

There are a number of possibilities

  • You may have set the routes wrong
  • The Facebook Redirect Url you specified might be wrong
0
On

First you need to create the FB project and you will have the client_id (App ID) and secret_key (App secret)

In your services configuration file: config/services.php you need to specify the facebook key like this:

'facebook' => [
    'client_id' => 'client_id from fb',
    'client_secret' => 'secret_key from fb',
    'redirect' => 'http://your_site/your_fb_login_ok_path',
],

then you create the route:

Route::get('your_fb_login_ok_path', function ($facebook = "facebook")
{
    // Get the provider instance
    $provider = Socialize::with($facebook);

    // Check, if the user authorised previously.
    // If so, get the User instance with all data,
    // else redirect to the provider auth screen.
    if (Input::has('code'))
    {
        $user = $provider->user();

        return var_dump($user);
    } else {
        return $provider->redirect();
    }
});

This should do it.

Then remember to add this URL to your facebook redirect: http://your_site/your_fb_login_ok_path That is the URL that FB will redirect you to after successful login.