Blogs Hub

by AskGif | Aug 29, 2019 | Category :coding

Implementing Oauth Login for Linkedin, Facebook, Google and Microsoft

Implementing Oauth Login for Linkedin, Facebook, Google and Microsoft

<p>Introducing the new lightweight OAuth Login commercial edition, an OAuth login system for your website with Facebook, Google, Microsoft and Linkedin. OAuth Login is very quick and powerful, sure this helps you to increase your web project registrations. It's definitely a must-have login system for every PHP based web projects. Hardly it will take 10 mins for installation.</p> <p>&nbsp;</p> <p>Database</p> <p>Users table database design.</p> <pre class="language-javascript"><code>CREATE TABLE IF NOT EXISTS `users` ( id INT(11) NOT NULL AUTO_INCREMENT, email VARCHAR(200) , name VARCHAR(200) , first_name VARCHAR(200) , last_name VARCHAR(200) , gender VARCHAR(10) , birthday VARCHAR(20) , location VARCHAR(200) , hometown VARCHAR(200) , bio TEXT, relationship VARCHAR(30) , timezone VARCHAR(10) , provider VARCHAR(10) , provider_id INT(30) , picture TEXT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;</code></pre> <p>&nbsp;</p> <p>The script contains three folders called facebook_lib, google_lib, microsoft_lib, linkedin_lib and images with PHP files.</p> <pre class="language-markup"><code>facebook_lib //Facebook OAUTH library -- config.php //Facebook app configuration file. google_lib //Google OAUTH library -- config.php //Google app configuration file. microsoft_lib //Microsoft OAUTH library -- config.php //Microsoft app configuration file. linkedin_lib //Linkedin OAUTH library -- config.php //Linkedin app configuration file. images db.php //Database connection OauthLogin.php //Class facebook_login.php //Facebook Login google_login.php //Google Login microsoft_login.php //Microsoft Login linkedin_login.php //Linkedin Login index.php home.php header.php redirect.php logout.php </code></pre> <p>&nbsp;</p> <p>How to Use</p> <p>Just call anchor tag with particular service login file.&nbsp;</p> <pre class="language-markup"><code>&lt;a href='facebook_login.php'&gt;Facebook Login&lt;/a&gt; &lt;a href='google_login.php'&gt;Google Login&lt;/a&gt; &lt;a href='microsoft_login.php'&gt;Microsoft Login&lt;/a&gt; &lt;a href='linkedin_login.php'&gt;Linkedin&lt;/a&gt;</code></pre> <p>&nbsp;</p> <p>Installation</p> <p>In this script just you have to modify three files.</p> <p>&nbsp;</p> <p>db.php</p> <p>Database configuration file, modify MySQL server details.</p> <pre class="language-javascript"><code>&lt;?php $mysql_hostname = "localhost"; $mysql_user = "username"; $mysql_password = "password"; $mysql_database = "databasename"; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database"); mysql_select_db($mysql_database, $bd) or die("Could not select database"); $base_url='http://www.yourwebsite.com/'; ?&gt;</code></pre> <p>&nbsp;</p> <p>Facebook Configuration facebook_lib/config.php</p> <p>You have to create an application. Facebook will provide you app id and app secret id, just replace in the following code.</p> <p>fbconfig.php</p> <pre class="language-javascript"><code>&lt;?php $facebook_appid='App ID'; $facebook_app_secret='App Secret'; $facebook_scope='email,user_birthday'; $facebook = new Facebook(array( 'appId' =&gt; $facebook_appid, 'secret' =&gt; $facebook_app_secret, )); ?&gt;</code></pre> <p>&nbsp;</p> <p>Google Configuration google_lib/config.php</p> <p>You can find this in google_lib folder, here you have to configure application OAuth keys, Consumer keys, and redirection callback URL.</p> <pre class="language-javascript"><code>// OAuth2 Settings, you can get these keys at https://code.google.com/apis/console Step 6 keys 'oauth2_client_id' =&gt; 'Client ID', 'oauth2_client_secret' =&gt; 'Client Secret', 'oauth2_redirect_uri' =&gt; 'http://www.yoursite.com/google_login.php', // OAuth1 Settings Step 3 keys. 'oauth_consumer_key' =&gt; 'OAuth Consumer Key', 'oauth_consumer_secret' =&gt; 'OAuth Consumer Secret',</code></pre> <p>&nbsp;</p> <p>Microsoft Configuration microsoft_lib/config.php</p> <p>Microsoft will provide you Client_Id and Client_Secret.</p> <p>fbconfig.php</p> <pre class="language-javascript"><code>&lt;?php //Microsoft Application Settings $microsoft_client_id='Client ID'; $microsoft_client_secret='Client Secret'; $microsoft_scope='wl.basic wl.emails wl.birthday'; $microsoft_redirect_url=$base_url.'microsoft_login.php'; )); ?&gt;</code></pre> <p>&nbsp;</p> <p>Linkedin Configuration linkedin_lib/config.php</p> <p>provide your App_Key and App_Secret.&nbsp;</p> <p>fbconfig.php</p> <pre class="language-javascript"><code>&lt;?php //Linkedin Application Settings $linkedin_appKey='App Key'; $linkedin_appSecret='App Secret'; $linkedin_callbackUrl=$base_url.'linkedin_login.php'; )); ?&gt;</code></pre>

read more...