Laravel Login with Linkedin using Socialite Package
By Hardik Savani May 27, 2016 Category : Laravel Linkedin APIPauseUnmuteLoaded: 4.16%FullscreenIn my previous post i added login with google and login with facebook, that's very simple and almost same but if you doing from scratch then it's important to write all. So in this post we will login with Linkedin. In this post i want to share with you how to do sign in with Linkedin and how to do sign up with Linkedin. Laravel 5 provide very easy way to implement login with your Linkedin account and register with your Linkedin id. Laravel 5 provide us Socialite package that is help to social authentication. In this post we will make example same as like bellow preview and you can do that easily by using few following step:
Preview:
Step 1: Installation
In first step we will install Socialite Package that provide Linkedin api to connect with Linkedin account. So, first open your terminal and run bellow command:
composer require laravel/socialite
After install above package we should add providers and aliases in config file, Now open config/app.php file and add service provider and aliase.
In this step we need Linkedin client id and secret that way we can get information of other user. so if you don't have Linkedin app account then you can create from here : Linkedin Developers App. you can find bellow screen :
Now you have to click on Create Application and fill form details and create new application. after created application you can see following slide:
and you can copy client id and secret.
Now you have to set app id, secret and call back url in config file so open config/services.php and set id and secret this way:
In this step first we have to create migration for add linkedin_id in your user table. so le's craete new migration and bellow column this way:
Migration
Schema::table('users', function ($table) { $table->string('linkedin_id');});
After adding linkedin_id column first we have to add new route for linkedin login. so let's add bellow route in routes.php file.
app/Http/routes.php
Route::get('linkedin', function () { return view('linkedinAuth');});Route::get('auth/linkedin', 'Auth\AuthController@redirectToLinkedin');Route::get('auth/linkedin/callback', 'Auth\AuthController@handleLinkedinCallback');
After add route, we need to add method of linkedin auth that method will handle linkedin callback url and etc, first put bellow code on your AuthController.php file.