Skip to main content

Login with Microsoft Live Account PHP

How to Login with Microsoft Live Account PHP



This post explains you how to implement login Microsoft Live account using PHP.

For login ,  we need  Client Secret Key and Client ID . Click Here To create Microsoft application that will provide client id and password.

Open the above url and fill "app name" and "redirect url" .

Application id is your client ID and application secret is client secret key.

Our api is created successfully.

Now we need to create 2 php pages one for login and second one for receive user data as response from microsoft app.

First create a link on your login page , that will redirect to user on our microsoft login page(mslogin).
<a href="mslogin.php">Login with Microsoft</a>


Then create a page mslogin.php and paste below code

mslogin.php
<?php
$client_id = "YOUR-CLIENT-ID";
$redirect_uri = "https://your-site.com/response.php"; //you can also use localhost url for testing but first add url into microsoft app redirect url then you can use localhost url
 $urls = 'https://login.live.com/oauth20_authorize.srf?client_id='.$client_id.'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails&response_type=code&redirect_uri='.$redirect_uri;
  header("Location: " .$urls);
?>

Now when user click on that link then he will redirect to microsoft login page and after login through microsoft he will redirect to our response url . we already saved redirect url into our app.

Now create response.php
<?php
   if(isset($_GET['code']) && $_GET['code']!="") {
    $auth_code = $_GET["code"];
    $client_id = "YOUR-CLIENT-ID";
    $client_secret = "Your-API-PASSWORD";
    $redirect_uri = "https://your-site.com/response.php"; 

    $fields=array(
        'code'=>  urlencode($auth_code),
        'client_id'=>  urlencode($client_id),
        'client_secret'=>  urlencode($client_secret),
        'redirect_uri'=>  urlencode($redirect_uri),
        'grant_type'=>  urlencode('authorization_code')
    );

    $post = '';
    foreach($fields as $key=>$value) { $post .= $key.'='.$value.'&'; }
    $post = rtrim($post,'&');
    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL,'https://login.live.com/oauth20_token.srf');
    curl_setopt($curl,CURLOPT_POST,5);
    curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    $result = curl_exec($curl);
    curl_close($curl);
    $response =  json_decode($result);
    $accesstoken = $response->access_token;
    $get_profile_url='https://apis.live.net/v5.0/me?access_token='.$accesstoken;
    $xmlprofile_res=curl_file_get_contents($get_profile_url);
    $profile_res = json_decode($xmlprofile_res, true);

    if($profile_res) {
        echo "<pre>"; print_r($profile_res); echo "</pre>"; //this will print output of user info
        $userid = $profile_res['id'];
        $login_name = $profile_res['name'];
        $fname = $profile_res['first_name'];
        $lname = $profile_res['last_name'];
        $email = $profile_res['emails']['account'];
    }    
  } 
?> 

Now run your mslogin.php and try to login with microsoft live ID. oh it works great.  :)

Comments

  1. Did you hear there is a 12 word phrase you can communicate to your crush... that will induce deep feelings of love and instinctual attraction to you buried within his chest?

    That's because hidden in these 12 words is a "secret signal" that triggers a man's instinct to love, adore and guard you with his entire heart...

    12 Words Will Fuel A Man's Desire Instinct

    This instinct is so hardwired into a man's mind that it will drive him to try harder than ever before to build your relationship stronger.

    Matter-of-fact, fueling this powerful instinct is absolutely binding to having the best possible relationship with your man that the instance you send your man a "Secret Signal"...

    ...You'll immediately find him expose his mind and soul to you in a way he never expressed before and he'll recognize you as the one and only woman in the galaxy who has ever truly understood him.

    ReplyDelete
  2. Your Affiliate Money Printing Machine is waiting -

    And getting it set up is as simple as 1..2..3!

    Here is how it works...

    STEP 1. Input into the system which affiliate products you want to promote
    STEP 2. Add PUSH BUTTON TRAFFIC (this LITERALLY takes 2 minutes)
    STEP 3. Watch the system grow your list and sell your affiliate products all for you!

    So, do you want to start making profits???

    Check it out here

    ReplyDelete
  3. This is how my friend Wesley Virgin's autobiography begins with this SHOCKING AND CONTROVERSIAL video.

    Wesley was in the army-and soon after leaving-he found hidden, "self mind control" secrets that the CIA and others used to get everything they want.

    As it turns out, these are the EXACT same methods many celebrities (notably those who "come out of nowhere") and top business people used to become wealthy and famous.

    You probably know how you utilize only 10% of your brain.

    That's mostly because the majority of your brain's power is UNCONSCIOUS.

    Perhaps this conversation has even taken place INSIDE OF YOUR very own brain... as it did in my good friend Wesley Virgin's brain 7 years back, while driving an unlicensed, beat-up garbage bucket of a vehicle with a suspended license and $3 in his bank account.

    "I'm absolutely fed up with living paycheck to paycheck! When will I finally make it?"

    You took part in those types of conversations, ain't it so?

    Your own success story is going to be written. You just have to take a leap of faith in YOURSELF.

    Take Action Now!

    ReplyDelete
  4. function curl_file_get_contents($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
    $data = curl_exec($curl);
    curl_close($curl);
    return $data;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Run and compile sass scss file to css using node

  Today we learn how to use scss and generate css using node  or Run and compile sass scss file to css using node   So please follow simple  steps :-   Today we will create a project that can read scss file and generates css with it  Note: Make sure you have installed node in your system. If you want to help to install node js based on your system then check our other tutorial or check node js official website. Now create a blank folder and open  terminal(linux) or cmd(windows) and navigate to your current project folder by using cd command Now run below command npm init after enter it will ask you some package info that you can fill according to you or just keep enter until it finished. The above command will generate package.json file Now  we will install npm module that will convert our scss to css Run below command: npm install node-sass So we have installed node-sass package . Now open package.json file in your editor and add below code into it into

How to retrieve Facebook Likes, share , comment Counts

function facebook_count($url){     // Query in FQL     $fql  = "SELECT share_count, like_count, comment_count ";     $fql .= " FROM link_stat WHERE url = '$url'";     $fqlURL = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql);     // Facebook Response is in JSON     $response = file_get_contents($fqlURL);     return json_decode($response); } $fb = facebook_count('https://www.facebook.com/BahutHoGyiPadhai'); // facebook share count echo $fb[0]->share_count;  echo "like"; // facebook like count echo $fb[0]->like_count ; echo "comment"; // facebook comment count echo $fb[0]->comment_count;  ?>

jQuery Datatable add date range filter

jQuery Datatable add date range filter Datatable is most useful jQuery plugin that helps to make our html tables more powerful and give powers to user to filter , search, sort, pagination etc, But Data table provides a common filter only and yes we can customize and add filter for each column, but still sometimes we need an advance filter like show results only between a date range, So today we will learn how to create a minimum and maximum date range fields and show date picker on it, and user can fill dates by selecting dates and data table will auto filter records based on it. Keep follow below steps :- I am using Bootstrap if you want to use any other framework then you can use. Create a new index.php file  and paste below code in it, i have used all required CDN like bootstrap, datatable, datepicker etc. <!DOCTYPE html> <html> <head>     <title>Datatable Date Range Filter Example</title>     <link rel="stylesheet" href="https://maxcd