People like to login into any website using their social network accounts like Facebook, Twitter, Google, LinkedIn. It’s easy because user doesn’t have to fill lengthy forms, confirm their email address. Now many big websites support APIs for users to authenticate and login to any website. Now we are going to learn how users can Login to website using their LinkedIn.Com Account using PHP.
So now here is step by step tutorial on how to integrate login system with LinkedIn API using PHP.
We need to make new application on LinkedIn. Go to http://LinkedIn.com and Create a New Application.
Fill out the form to register a new application.
Application was created successfully. And copy API Key & Secret Key somewhere because it will be used in Application.
Download the code from above download button. Here is the folder structure for better understanding. We will edit only config.php for our login system to work.
| — linked-login.png //user login image
| — class.linkedClass.php
| — config.php // change the API key, Secret key base URL &
| — linkedinoAuth.php
| — OAuth.php
Edit Config.PHP and insert the API key and secret key that we obtained earlier from LinkedIn.
//linkedin configuration for Oauth
$config['linkedin_access'] = 'api key';
$config['linkedin_secret'] = 'secret key';
$config['base_url'] = '/';
$config['callback_url'] = '/authorize_success.php';
Change the base_url & callback_url as required.
Now run this demo script on your hosting and open example.php like this. http://yourdomain.com/linkedin/example.php.
This will show you similar page with button for user to click and login with LinkedIn.Com. Now when user clicks the login with LinkedIn button. It will take you to LinkedIn.Com website for authorization. See example below.
Click Allow Access button. It will redirect user back to authorize_success.php.
Now user access credentials can be saved in database for future use. And all information that LinkedIn sends back will be printed on the page by authorize_success.php.
Example screenshot below.
Please check out demo to understand properly the sequence and working of script.