Search code examples
phplaravelfacebook-loginlaravel-socialite

Laravel facebook login using socialite


Please check the website here egypt-pets.com/login click on the facebook login and check the error page.

My routes

Route::get('login/facebook', 'Auth\LoginController@redirectToProvider');
Route::get('login/facebook/callback{token}', 'Auth\LoginController@handleProviderCallback');

My services.php

'facebook' => [
        'client_id' => '**********',
        'client_secret' => '**********',
        'redirect' => 'http://egypt-pets.com/auth/facebook/callback',
    ],

What I have tried

I have tried to check the facebook app but everything is right. Also I check the client_sercret and client_id but both are correct!


Solution

  • Facebook returns to this url of yours

    /auth/facebook/callback

    And your routes file says

    /login/facebook/callback

    This portion in your routes file is incorrect

    Route::get('login/facebook/callback{token}', 'Auth\LoginController@handleProviderCallback');

    You can try this:

    Route::get('auth/facebook/callback', 'Auth\LoginController@handleProviderCallback');
    

    And then to get the callback token you can use the following code in your controller.

    $code = \Request::input('code');
    

    Hope this helps;