Brooke  Giles

Brooke Giles

1568081046

Laravel 6 Social Login Tutorial - Login with Github

Originally published at https://w3path.com

We will discuss how to add a Github social button in your Laravel 6 projects and how to simple authenticate (log in) users using the Github Login button in our Laravel app also we learn GitHub register. We will show you each thing step by step.

Contents

  • Install Laravel App
  • Setup Database
  • Download Socialite Package
  • Get Secrets from Github
  • Make Route
  • Create Controller & Methods
  • Create Blade View
  • Start Development Server
  • Conclusion

Install Laravel App

Now, we need to download Laravel the latest fresh setup. Use the below command and download fresh new Laravel setup :

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

Setup Database

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

 DB_CONNECTION=mysql 
 DB_HOST=127.0.0.1 
 DB_PORT=3306 
 DB_DATABASE=here your database name here
 DB_USERNAME=here database username here
 DB_PASSWORD=here database password here

Download Socialite Package

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

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…
 Laravel\Socialite\SocialiteServiceProvider::class,
],

‘aliases’ => [
// Other aliases…
‘Socialite’ => Laravel\Socialite\Facades\Socialite::class,
],

Get Secrets from Github

First of all, We need to required the CLIENT ID and CLIENT SECRET to add a social Github login button in the Laravel based project, let’s go to https://github.com/settings/developers and create a new app. We have put app name, description, website name, and callback URL on this page :

You will see your dashboard. Now get the following CLIENT ID and CLIENT SECRET.

After successfully create an app in Github and get credentials from Github dashboard, Set client id and client secret config/service.php file :

 ‘github’ => [
    ‘client_id’ => ‘xxxx’,
    ‘client_secret’ => ‘xxx’,
    ‘redirect’ => ‘http://127.0.0.1:8000/callback/github’,
  ],

Go to app/User.php and set fillable property put the below code here :

protected $fillable = [
‘name’, ‘email’, ‘password’, ‘provider’, ‘provider_id’
];

Next step, Go to app/database/createuserstable.php and put the below code here :

<?php
 
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) {
            $table->increments(‘id’);
            $table->string(‘name’);
            $table->string(‘email’)->unique()->nullable();
            $table->string(‘provider’);
            $table->string(‘provider_id’);
            $table->timestamp(‘email_verified_at’)->nullable();
            $table->string(‘password’)->nullable();
            $table->rememberToken()->nullable();
            $table->timestamps();
        });
    }
 
    /**
     
Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists(‘users’);
    }
}

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()
{
    Schema::defaultStringLength(191);
}

 Next, migrate the table using the below command :

php artisan migrate

Make Route

We will create two routes in the web.php file. Go to app/routes/web.php file and create two below routes here :

 Route::get(‘/auth/redirect/{provider}’, ‘SocialController@redirect’);
Route::get(‘/callback/{provider}’, ‘SocialController@callback’);

Create Controller

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 : 

<?php
 
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);
 
        auth()->login($user);
 
        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;
   }
}
Add social Github buttons in login and register blade view

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

<hr>
<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>
    </div>
</div>

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

<hr>
<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>
    </div>
</div>

Start Development Server

We need to start the 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 6 examples so run bellow command to quick run.

 http://127.0.0.1:8000/login
Or direct hit in your browser
http://localhost/blog/public/login

Conclusion

In this tutorial, We have successfully login using the github button in the Laravel 6 based application. our examples run quickly.

Live Demo

laravel 6 GitHub login example looks like this :

Laravel Github login screen :

Github Authentication Screen :

Github Register Screen Laravel :

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

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow me on Facebook | Twitter

Further reading

Laravel 5.8 Tutorial for Beginners

What’s New in Laravel 6.0

Laravel 6 Tutorial - How to make Auth in Laravel 6

Laravel 6 Authentication Tutorial: Login/Register/Password Reset UI




#laravel #php #web-development #security

What is GEEK

Buddha Community

Laravel 6 Social Login Tutorial - Login with Github

I am Developer

1617089618

Laravel 8 Tutorial for Beginners

Hello everyone! I just updated this tutorial for Laravel 8. In this tutorial, we’ll go through the basics of the Laravel framework by building a simple blogging system. Note that this tutorial is only for beginners who are interested in web development but don’t know where to start. Check it out if you are interested: Laravel Tutorial For Beginners

Laravel is a very powerful framework that follows the MVC structure. It is designed for web developers who need a simple, elegant yet powerful toolkit to build a fully-featured website.

Recommended:-Laravel Try Catch

#laravel 8 tutorial #laravel 8 tutorial crud #laravel 8 tutorial point #laravel 8 auth tutorial #laravel 8 project example #laravel 8 tutorial for beginners

Laravel 6 CRUD Tutorial with Example

In this example, I will show you to how to make simple laravel CRUD(insert, update, delete or listing) operations with example.

Insert Update Delete module is primary requirement for each project,you will understand how to use route, controller, blade files, model and migration for crud operation in laravel 6.

We just need to follow below step and you will get basic CRUD using controller, model, route, bootstrap 4 and blade. If you follow below step then definatly you will get proper output.

Read More : Laravel 6 CRUD Tutorial with Example

https://www.techsolutionstuff.com/post/laravel-6-crud-tutorial-with-example

#laravel 6 crud tutorial with example #laravel 6 tutorial #crud tutorial #laravel #php #jquery

Laravel 8 Socialite Login with Google Account

Hello Guys,

Today I will share laravel 8 socialite login with google account. In this post give you example of laravel 8 socialite login with google account and also you can knowledge about how to socialite login with google account in laravel 8 jetstream.

This tutorial will give you very easy and simple example of login with gmail in laravel 8.

Read More : Laravel 8 Socialite Login with Google Account

https://websolutionstuff.com/post/laravel-8-socialite-login-with-google-account


Read More : How To Create Dynamic Pie Chart In Laravel

https://websolutionstuff.com/post/how-to-create-dynamic-pie-chart-in-laravel


Read Also : Stripe Payment Gateway Integration Example In Laravel 8

https://websolutionstuff.com/post/stripe-payment-gateway-integration-example-in-laravel-8

#laravel 8 socialite login with google account #laravel #laravel 8 login with google #login with gmail account #laravel socialite #login with gmail in laravel 8

I am Developer

1610191977

Angular 11 Google Social Login Example Tutorial

Angular 9/10/11 social login with google using angularx-social-login library example. In this tutorial, i will show you step by step on how to implement google social login in angular 11 app.

And also, this tutorial will show you How to login into Angular 10/11 application with google using angularx-social-login library in angular 11 app.

Google Login Integration In Angular 11 App

  • Step 1 - Create New Angular App
  • Step 2 - Install Social Login Library
  • Step 3 - Add Code on App.Module.ts File
  • Step 4 - Add Code on View File
  • Step 5 - Add Code On App.Component ts File
  • Step 6 - Start the Angular Google Login App

https://www.tutsmake.com/angular-11-google-social-login-example/

#angular 11 google login #angular 11 social-login example #login with google button angular 8/9/10/11 #angular 10/11 login with google #angular 10 social google login #angular social login google

I am Developer

1597563325

Laravel 7/6 Image Upload Example Tutorial

Laravel image upload example tutorial. Here, i will show you how to upload image in laravel 7/6 with preview and validation.

Before store image into db and folder, you can validate uploaded image by using laravel validation rules. as well as you can show preview of uploaded image in laravel.

Image Upload In Laravel 7/6 with Validation

Image upload in laravel 7/6 with preview and validation. And storage image into folder and MySQL database by using the below steps:

Install Laravel Fresh App
Setup Database Details
Generate Image Migration & Model
Create Image Upload Route
Create Image Controller
Create Image Upload and Preview Blade View
Start Development Server

https://www.tutsmake.com/laravel-7-6-image-upload-with-preview-validation-tutorial/

#laravel 7 image upload example #laravel upload image to database #how to insert image into database in laravel #laravel upload image to storage #laravel image upload tutorial #image upload in laravel 7/6