Search code examples
phplaravelsocial-authentication

Social authentication in laravel


I am trying to authenticate using social authentication in laravel. I have this code in services.php

'facebook' => [
        'client_id' => 'your-facebook-id',
        'client_secret' => 'your-facebook-app-secret',
        'redirect' => 'http://your-callback-url',
        ],

And whenever i try to login the facebook shows:

Invalid App ID: your-facebook-id

What actually are client_id, client_secret, and redirect here?

I have these methods for redirecting the user to the OAuth provider, and another for receiving the callback from the provider after authentication.

public function redirectToProvider()
{
     return Socialite::driver('facebook')->redirect();
}

public function handleProviderCallback()
{
     $user = Socialite::driver('facebook')->user();
     dd($user->getEmail);
}

Solution

  • You get the client_id and the client_secret from Facebook when you create an "app" in their system (In this context an app isn't what you might think initially).

    https://developers.facebook.com/

    Once created, your client_id will be what they call "App ID" and your client_secret will be what they call "App Secret". You need to click the "Show" button and re-authenticate to get hold of your secret.

    Your redirect is where you want Facebook to redirect you after the user has authorised your app. Generally this redirect should be where you're actually handling the login process, which in your case is the URL/route that passes control to your handleProviderCallback() method.