Skip to main content

How to implement LinkedIn login in laravel

In this tutorial, we’re going to explain how to integrate LinkedIn login in Laravel based application using Socialite. The Socialite is Laravel’s official package, which is making is easy to authenticate with external services with OAuth providers.

Create Project

Create a brand new Laravel 5.6 project with Composer create-project command:

Database connection settings

After creating project open .env file and update your database credentials:
Next step, would be, go to the project root and open the terminal and type the following command. It will create the two tables, which is by default ships by Laravel 5.6
You might get following error :
PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes”)
to fix this, all you have to do is to edit your AppServiceProvider.php file and add to the boot method a default string length:
Lets add two new columns called provider_id, provder to the users table, create a migration file with below commnad
Open create migration file and update it as shown below
NOTE: Changing columns for table “users” requires Doctrine DBAL; so install “doctrine/dbal” with composer
Again run the php artisan migrate command from the project root. It will add new columns to the user table and it will modify email and password default values to null.
Now update your user model fillable array as shown below, with new columns

Installing Socialite

To get started with Socialite, use Composer to add the package to your project’s dependencies:
Log in to your LinkedIn developer account and create an application and grab the client id and client secret. Open your config/services.php configuration file and place credential inside it as shown below.
(In real app place config values in the .env file, it is a good practice).
so let’s define callback and redirect routes in routes/web.php file:
Create a controller called SocialAuthController with following artisan command
Now update your controller with below code:
Now update view file welcome.blade with below code:
That’s it, now start the application with php artisan serve, and access your application http://localhost:8000.

Comments

Popular posts from this blog

Build chatbot with node js and react js

User Experience is given a lot of attention while building any application these days. More and more brands are leveraging chatbots to service their customers, market their brand, and even sell their products. There are a lot of awesome tools out there which helps in building an intelligent bot very easily like Google’s DialogFlow, Amazon Lex, etc, most of which implement their own Natural Language Processing (NLP) logic. However, in some cases, we don’t really need an intelligent bot. Whenever we have a small application having a limited set of options to choose from, it’s not really necessary to use NLP based tools like Google’s DialogFlow. You need to integrate with them (which is pretty easy though), and you need to make a network call to get the results. Instead, you would want to define your rules locally in those cases. Here we will build a simple chatbot using React Simple Chatbot library and add it to our pizza-builder app using which we can build ou...

PHP Image Upload with Size Type Dimension Validation

File upload feature requires basic validations to  make clean and hygienic  the user input. There is a huge chance of exploiting a file upload option with malicious intent. Improper implementation of a file upload input increases security vulnerability. We need to validate the uploaded files before saving them on the server to reduce the vulnerability. I have created a HTML form and provided an option to upload files. When the form is submitted, the file binaries are sent to the PHP and validated in the server side. I have checked if the uploaded file is an image and I have specified the allowed image extension, size and dimension based on which the validation is taking place. After all these validations have passed, the image file is saved in the target location as specified. The server-side image file validation takes place in the following aspects. If the file is not empty. If the file extension is one of .jpg, .png, .jpeg. If the file size is le...

PHP in Website Development Era

If you guys are watching this page its sure you want to check more about PHP.PHP language has a unique place in website development. It was introduced at a right time when web-based business was in new trend. Over a period it became one of the popular languages for creating web applications. The reasons are, simple language structure unique features  free license. PHP’s  unique features  lead to more popularity. Since 1994 when PHP development was started, we have seen the following version releases. PHP Versions Versions Key Features Description PHP/FI (1995) Form handling Perl/CGI script (PHP 1.0) introduced by  Rasmus Lerdorf . The Expansion is  Personal Home Page / Form Interpreter . PHP/FI2 (1997) Data conversion Form data export With slight modifications in Form Interpreter(PHP 2.0) to handle form entries. PHP  3 – (1998) PHP core is rewritten PHP parser is rewritten. Zend Engine is incorporated. Language core wa...