Laravel Socialite Github Login Example

Laravel Socialite Github Login Example

In this laravel 5.7 social login tutorial – We would like to share with you, How can we implement github social login in your Laravel based project using laravel 5.7 socialite package. And also work with laravel 5.8 version. Github login also work with laravel 5.7,5.8 versions.

We will discuss how to add github social button in your laravel 5.7 project and how to simple authenticate (login) users using Github Login button in our laravel app also we learn github register. We will show you each things step by step.

Laravel Github Login Tutorial

  • Install Laravel App
  • Setup Database
  • Download Socialite Pacakage
  • Add Fillable In Model
  • Create Auth Files
  • Create Github App For Auth
  • Add Github App Detail
  • Make Route
  • Create Controller & Methods
  • Add Login Button Blade View
  • Start Development Server

1: Install Laravel App

First of all, we need to download laravel latest fresh setup. Use the below command and download fresh new laravel setup :

composer create-project --prefer-dist laravel/laravel GithubLogin

2: Setup Database

After successfully install laravel 5.7 Application, Go to your project .env file and set up database credential :

DB_DATABASE=here your database name here
DB_USERNAME=here database username here
DB_PASSWORD=here database password here

3: Download Socialite Pacakage

In this step, we will install socialite package using the below commmand :

composer require laravel/socialite

After successfully install socialite package, we need to configure the aliese and provider in config/app.php :

'providers' => [
// Other service providers…

'aliases' => [
// Other aliases…
'Socialite' => Laravel\Socialite\Facades\Socialite::class,

4: Add Fillable In Model

Go to app/User.php model file and set fillable property like the following:

protected $fillable = [
'name', 'email', 'password', 'provider', 'provider_id'

5: Create Auth Files

Before, we create auth files by artisan command. We need to go database/migrations/create_users_table.php fileand put the below code here in it:


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('users', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

Now, we need to create authentication using below command:

php artisan make:auth

Before we run php artisan migrate command go to app/providers/AppServiceProvider.php and put the below code :

use Illuminate\Support\Facades\Schema;
function boot()

Next, migrate the table using the below command:

php artisan migrate

6: Create Github App For Auth

Now, create github app by visiting this url

1: When you visit the above url, you will see like the following:

create github app

2: After login or signup in, Then you will see like in the below picture. So, you need to click New Auth APP button. And Create your app:

create oauth app in github

3: After that, Register a new OAuth application page will open. So fill your app detail and submit it, look like in below picture:

register oauth github app

4: Finally, you will see dashboard of your created github app look like in below picture. So copy your github app details here:

get github app client id and secret

7: Add Github App Detail

In this step, add GitHub app details into service.php file. So, open laravel github social login project in any text editor. Then navigate config directory and open service.php file. Then add the client id and secret got from github app into service.php file:

 'github' => [
    'client_id' => 'xxxx',
    'client_secret' => 'xxx',
    'redirect' => '',

8: Make Route

Here, we will create two routes in web.php file. Go to /routes/web.php file and add the following routes into web.php file:

 Route::get('/auth/redirect/{provider}', '[email protected]');
Route::get('/callback/{provider}', '[email protected]');

9: Create Controller

Now, we need to create a controller name SocialController. Use the below command and create Controller :

php artisan make:controller SocialController

After successfully create controller go to app/controllers/SocialController.php and put the below code :


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator,Redirect,Response,File;
use Socialite;
use App\User;
class SocialController extends Controller
    public function redirect($provider)
        return Socialite::driver($provider)->redirect();

    public function callback($provider)
        $getInfo = Socialite::driver($provider)->user();
        $user = $this->createUser($getInfo,$provider);


        return redirect()->to('/home');

   function createUser($getInfo,$provider){

     $user = User::where('provider_id', $getInfo->id)->first();

     if (!$user) {
         $user = User::create([
            'name'     => $getInfo->name,
            'email'    => $getInfo->email,
            'provider' => $provider,
            'provider_id' => $getInfo->id
      return $user;

10: Add Login Button Blade View

In this step, we need to add social Github buttons in login and register blade view file.

Navigate to Resources/Views/Auth/register.blade.php and add a Github social login button :

<div class="form-group row mb-0">
     <div class="col-md-8 offset-md-4">
        <a href="{{ url('/auth/redirect/github') }}" class="btn btn-primary"><i class="fa fa-github"></i> Github</a>

In Resources/Views/Auth/login.blade.php and add a github social login button :

<div class="form-group row mb-0">
     <div class="col-md-8 offset-md-4">
        <a href="{{ url('/auth/redirect/github') }}" class="btn btn-primary"><i class="fa fa-github"></i> Github</a>

11: Start Development Server

In this step, we need to start development server. Use the php artisan serve command and start your server :

 php artisan serve

Now we are ready to run our github login laravel 5.7 example .so run bellow command to quick run.
Or direct hit in your browser


In this tutorial, We have successfully login using github button in laravel 5.7 based application. our examples run quickly.

Laravel 5.7 github login example look like this :

Laravel Github login screen :

laravel social login

Github Authentication Screen :

github login laravel

Github Register Screen Laravel :

social login laravel

If you have any questions or thoughts to share, use the comment form below to reach us.


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

One reply to Laravel Socialite Github Login Example

  1. Superb tutorials sir
    please sir share project source code link

Leave a Reply

Your email address will not be published. Required fields are marked *