Few months back Microsoft has launched OAuth system for client websites, using this you can get the valid user details from Hotmail and Outlook database. Earlier I had published Facebook, Google and Twitter OAuth login systems, now this post explains you how to implement Microsoft Live OAuth connect using PHP. Sure this helps your web project to avoid registration email activation.
![Login with Microsoft Live OAuth Connect](https://lh6.googleusercontent.com/-TiERxGIyUQc/UPpD4oH5L2I/AAAAAAAAHHE/P7oc1vwieGE/s550/MicrosoftLogin.png)
![](http://lh3.ggpht.com/_N9kpbq3FL74/Sd31pMC1aHI/AAAAAAAABg8/UAWFBvpGO6Y/down.png)
The tutorial contains one folder called lib with five PHP files.
lib
-- http.php
-- oauth_client.php //OAuth client library
index.php
home.php
microsoft_login.php // Microsoft login file
db.php
logout.php
-- http.php
-- oauth_client.php //OAuth client library
index.php
home.php
microsoft_login.php // Microsoft login file
db.php
logout.php
Previous Posts
Google Account OAuth and Facebook and Twitter and
Facebook and Google OAuth System
Database
Sample database users table columns id, email, oauth_uid, oauth_provider and username.
CREATE TABLE users
(
id INT PRIMARY KEY AUTO_INCREMENT,
full_name VARCHAR(200),
first_name VARCHAR(100),
last_name VARCHAR(100),
email VARCHAR(200),
gender VARCHAR(10),
birthday VARCHAR(20),
provider_id VARCHAR(100)
);
(
id INT PRIMARY KEY AUTO_INCREMENT,
full_name VARCHAR(200),
first_name VARCHAR(100),
last_name VARCHAR(100),
email VARCHAR(200),
gender VARCHAR(10),
birthday VARCHAR(20),
provider_id VARCHAR(100)
);
Step 1: Create Microsoft Application
Click here to launch Microsoft live development dashboard and click create application link.
![Login with Microsoft Live OAuth Connect](https://lh5.googleusercontent.com/-vJq8tJ-Qu74/UPuo9xIeY1I/AAAAAAAAHH0/1sXKup3lZJE/s550/One.png)
Step 2: Add your domain
Microsoft will provide you Client ID and Client secret. Give valid redirect callback URL.
![Login with Microsoft Live OAuth Connect](https://lh4.googleusercontent.com/-60ZM-ujVYoQ/UPupCXgPU8I/AAAAAAAAHH8/UTcvrxdju2s/s372/Screen%2520Shot%25202013-01-20%2520at%252012.10.26.png)
Step 3: Basic Information
Give your application details.
![Login with Microsoft Live OAuth Connect](https://lh3.googleusercontent.com/-dJvo7ozmaZE/UPupCn2hSGI/AAAAAAAAHIA/HuzsNeDtzuQ/s484/Screen%2520Shot%25202013-01-20%2520at%252012.11.29.png)
microsoft_login.php
You have to modify client_id and client_secret values.
$client->redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].
dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/microsoft_login.php';
$client->client_id = 'Microsoft Client ID';
$client->client_secret = 'Microsoft Client Secret';
dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/microsoft_login.php';
$client->client_id = 'Microsoft Client ID';
$client->client_secret = 'Microsoft Client Secret';
home.php
Contains PHP code inserting Microsoft OAuth session details into users table.
<?php
session_start();
include('db.php'); //Database Connection.
if (!isset($_SESSION['userdata'])) {
// Redirection to application home page.
header("location: index.php");
}
else
{
$userdata=$_SESSION['userdata'];
$name =$userdata->name;
$microsoft_id =$userdata->id;
$first_name =$userdata->first_name;
$last_name =$userdata->last_name;
$gender=$userdata->gender;
$email=$userdata->emails->account;
$email2=$userdata->emails->preferred;
$locale=$userdata->locale;
$birth_day=$userdata->birth_day.'-'.$userdata->birth_month.'-'.$userdata->birth_year;
$sql=mysql_query("insert into users(full_name,first_name,last_name,email,gender,birthday,provider_id) values("$name","$first_name","$last_name","$email","$gender","$birth_day","$microsoft_id")");
}
?>
session_start();
include('db.php'); //Database Connection.
if (!isset($_SESSION['userdata'])) {
// Redirection to application home page.
header("location: index.php");
}
else
{
$userdata=$_SESSION['userdata'];
$name =$userdata->name;
$microsoft_id =$userdata->id;
$first_name =$userdata->first_name;
$last_name =$userdata->last_name;
$gender=$userdata->gender;
$email=$userdata->emails->account;
$email2=$userdata->emails->preferred;
$locale=$userdata->locale;
$birth_day=$userdata->birth_day.'-'.$userdata->birth_month.'-'.$userdata->birth_year;
$sql=mysql_query("insert into users(full_name,first_name,last_name,email,gender,birthday,provider_id) values("$name","$first_name","$last_name","$email","$gender","$birth_day","$microsoft_id")");
}
?>
db.php
Database Configuration file.
<?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");
?>
$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");
?>
CREDITS: 9LESSONS.info
|
0 comments:
Post a Comment
Thanks For your comment.