Go Social with Laravel Socialite
- June 5, 2017
Ease for the customer is one principle that everyone strives towards. So onboarding a customer for the first time on the website should be seamless and smooth. Typical form based authentication is now a thing of the past. Customers want to go to the next steps with as less effort as possible and that is how Social Sign-up came into the picture.
So what is Social Sign-up?
Social Sign-up basically uses the data that you have provided to social networks like Facebook or Twitter in order to make you sign-up on some other website. This way you are saved the hassle of entering all information again for each website. If you are logged into Facebook in your browser then the sign-up is literally two clicks away!
But to do that you have to go and read documentation of each social networking website, follow the instructions, stick to specified format, etc. Not that it’s impossible, but it’s time-consuming and as a developer the most important thing you have is time! (that is why you have an ‘hourly’ rate).
What if I tell you that you don’t need to go to each and every famous social networking website, integrate individually and then troubleshoot and configure? What if I tell you that there is a simple and effective way to authenticate with OAuth providers?
No More What ifs, there is a way and that is Laravel Socialite.
Currently supporting Facebook, Twitter, Google, GitHub and Bitbucket, Laravel Socialite is the lean way of integrating social sign-up on your website, one more reason to use Laravel!
How to do that?
The best way would be to contact us and Hire the best Laravel PHP Developers in India from one of the Top Laravel PHP Development Company in India!
However, if you plan to go about your own, here is a sneak peak!
First you need to get your database ready! So you should set up a ‘users’ and a ‘password’ reset table. One note of caution though over here, since we are dealing with how to get multiple social network sign-ups, there might be a possibility of necessary data not getting returned as that might not be a compulsory field for that particular social network or due to some other reason. Hence, as a prevention to get any rogue errors, what one can do is make fields like ‘email’ (which some providers may not give) and things like ‘password’ (which we are not passing) nullable during the migration itself.
Then we need to add provider and provider_id since we are using multiple providers.
In order to get started with the service, we need to include the package in your JSON composer file and register the Laravel\Socialite\SocialiteServiceProvider in your app configuration file. We may also register a Facade for the same, which is basically a static proxy to the service container. A facade will basically help you with your syntax and maintaining flexibility and convenience at the same time.
Including packages in composer
Once this is done we need to add the actual credentials which are obtained from the respective social media platform providers. Do not that these need to be stored in the config/services.php and use the exact keywords for the provider that one needs to use.
github' => [
'client_id' => 'your-github-app-id',
'client_secret' => 'your-github-app-secret',
'redirect' => 'http://your-callback-url',
The app id and the secret keys are to be obtained from the respective social network developers portal.
That’s it! Now we are ready to sign up & authenticate users using multiple social media accounts! All we need to do now is configure two routes, one by which we redirect the user to the respective OAuth provider and then the other for receiving the response from the same whether the sign-up has happened or not.
The methods redirect and user take care of the same.
If you think this article was informative, do like and leave a comment below!
Contact Techuz for any Laravel PHP Development requirements!