Social Authentication with Socialite ― Laravel

Jaouad Ballat
Aug 28, 2017 · 2 min read

Laravel’s Socialite package makes it simple to authenticate your users to Facebook, Twitter, Google, LinkedIn, GitHub and Bitbucket.

In our case we’re going to login with github account

To get started with Socialite, use Composer to add the package to your project’s dependencies:

install laravel/socialite

Than register the Laravel\Socialite\SocialiteServiceProvider in your config/app.phpconfiguration file, providers section:

config/app.php

Next add the Socialite facade to the aliases array in the same configuration file:

config/app.php

You will also need to add credentials for the OAuth services your application utilizes that should be placed in your config/services.php configuration file, and should use the key github . For example:

config/services.php

Finally you will need two routes: one for redirecting the user to the OAuth provider, and another for receiving the callback from the provider after authentication. We will access Socialite using the Socialite facade:

LoginController

Once you have a user instance, you can grab a few more details about the user:

user informations
)
Jaouad Ballat

Written by

Full Stack Web Developer from Morocco. Telecommunications Engineering graduate. Been working in web development since graduation.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade