Tutorials , code & Inspiration

How to use Laravel Socialite in depth

Creating a social network app

The first thing you need to do is create an app which is used to log the user in. Apps are created on the social networking site, generally through their developer sub domain. In this example I will use Twitter, but the same process applies to Facebook, Github and Google.

For Twitter, go to https://apps.twitter.com/ and then select “Create a new app”. Fill in the required details for your app like the screen shot below. Use your own details, don’t forgot that if you are developing locally you can use a local url. Pay special attention to the callback url as we will be using it shortly.


Once this is done you will be presented with the App Id and App Secret, these are the details you need to make the connection for you user so that they can sign in. Laravel comes with a .env file which you can use to store all your sensitive environment variables. This is a good place to store the details of your app. Add the App Id and App Secret to this file so that your .env file contains the following:


Next go to your config/services.php file and add in the following array:

'twitter' => [
'client_id' => env('TWITTER_CLIENT_ID'),
'client_secret' => env('TWITTER_CLIENT_SECRET'),
'redirect' => 'http://yourwebsite.com/login/twitter',

Notice the redirect url matches the url we created in the app, this is important. Creating an app for Facebook, Google or Github follows the same process. Once it’s done you are ready to proceed.

Now that we’ve set up the app we are ready to authenticate the user

Chapter 2 of 7

Pin It on Pinterest