![]() In the LoginController, we set the scopes which are required to fetch basic information of a LinkedIn user. $authUser = User::where('provider_id', $user->id)->first() Public function findOrCreateUser($user, $provider) * If a user has registered before using social auth, return the user $authUser = $this->findOrCreateUser($user, $provider) $user = Socialite::driver($provider)->user() Public function handleProviderCallback($provider) * Obtain the user information from Linkedin. LoginController.php scopes()->redirect() In this file, we are writing methods that redirect users to the LinkedIn login, and on successful authorization, it will log the user in. The final adjustments will go in the LoginController.php file. LINKEDIN_CALLBACK_URL= Make sure to replace placeholders with their actual values. LINKEDIN_CLIENT_SECRET=YOUR_CLIENT_SECRET ![]() Now, add the LinkedIn credentials in the. 'redirect' => env('LINKEDIN_CALLBACK_URL'), 'client_secret' => env('LINKEDIN_CLIENT_SECRET'), 'client_id' => env('LINKEDIN_CLIENT_ID'), Upon library installation, open the config/services.php and add LinkedIn configuration as follows: 'linkedin' => [ Install this package using the command: composer require laravel/socialite The OAuth flow is handled by the package itself. All you need to do is follow the Socialite configuration steps. It comes with several adapters – Facebook, Twitter, LinkedIn, Google, etc. This package helps us to easily integrate the social login system in Laravel. Laravel has an official package called Socialite. You can change this route depending on your flow. home : User will redirect to this route after successful login with LinkedIn.Schema::create('users', function (Blueprint $table) /callback : The user will redirect to this route after authentication with LinkedIn. Open the users table migration file and add the code below. There is no guarantee of getting a user’s email after social login, so we should set the default value of the email column as ‘NULL’. The password column should have a ‘NULL’ value by default. In the case of social login, we don’t need to store passwords. ![]() The provider column will store the value ‘linkedin’ and provider_id will store the user’s social id(LinkedIn profile ID). To store this id I am adding 2 columns – provider and provider_id. When a user sign-in through LinkedIn, we will get the user’s LinkedIn profile ID. We are building a login system that requires storing user details in the database. composer create-project laravel/laravel linkedinloginĪfter installation, create the database and add the credentials to the. Here I am creating a project called ‘linkedinlogin’. Run the command below to install Laravel. I am going to install Laravel, create a ‘users’ table, and install the package required to integrate the social login system. Basic Configurationįor our tutorial, I will integrate LinkedIn login on the fresh Laravel installation. ![]() If you are looking for a Google or Twitter login then follow the linked articles. In this article, we will cover a login with LinkedIn in Laravel. Facebook, Twitter, Google, and LinkedIn are the popular options that are commonly used for social login on the website. We can rely on social sites and allow the user to use the system if they log in through a social site. Social sites verified users already so your application doesn’t need to perform the verification process again. The social login option on a website skips the verification process of a user. Adding a social login system on the website is a trend nowadays.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |