How to get Hotmail Contacts using Windows Delegated Authentication

From past one week i have been scratching head to fulfill one of my projects business requirement to get Hotmail Contacts email address using Windows Live Connect API but the LIVE connect developer SDK says due to privacy reasons we do not expose users contact email address. The Hotmail Contact API returns contact basic info along with EMAIL HASH which is of no use 🙁 .

After digging deep i found that there are couple of sites which are extracting Hotmail users contact Email Address. Like LinkedIn, EduGraph etc. On getting even deeper to understand how these sites are doing using some of the popular developer digging tools like the FIDDLER i got to know about the an OBSOLETE Microsoft API named DELEGATED AUTHENTICATION.

The Links related to Delegated Authentication clearly says :

This topic describes functionality that will be obsolete. This functionality is provided only to support legacy applications. Live Connect incorporates features that provide equivalent functionality.

Please note the last statement “Live Connect incorporates features that provide equivalent functionality”. BIG LIERS …….

On visiting LIVE connect developer guide reference it says:

Note  For user privacy reasons, we do not provide access to the email and address info of a user’s contacts.

Anyways somebody has to consolidate all this info for the benefit of others so let me take this opportunity for the sake of other developers…. 🙂

Steps to get Hotmail Contacts using Delegated Authentication:

Register Application

  1. Register your application using the link: RegisterApp.
  • Provide Application Name
  • Privacy Url – Note: The Url domain should be FQDN(Fully qualified domain name). You cannot provide “localhost” or IP in the Url.
  • Redirect domain – This Url will be the callback url of your application where microsoft will redirect user back after successful sign in and getting the necessary user consent for the data access in this case it will be “delauth-handler.aspx“. Note: The Url domain should be FQDN(Fully qualified domain name). You cannot provide “localhost” or IP in the Url.
  • Get the ClientId and ClientSecret. This will be the Gate pass for your application to communicate with Microsoft Contacts API.
  • Creating Sample App
    1. Create sample Website in IIS with fully qualified domain name. The domain name should be same as you provided in the RedirectUrl at the time of registering application. for ex: “www.HotmailLiveContacts.com”.
    2. Update the web.config file with:
    • wll_appid – This is the client Id you got after registering your application.
    • wll_secret – This is the client secret you got after registering your application.
    • wll_returnurl – This is the Redirect Url provided while registering your application.
    • wll_policyurl – This is the Policy Url provided while registering your application.
  • Get the consent url(login url) by initializing the “WindowsLiveLogin” class “GetConsentUrl” method. This is required to make the user login and provide necessary consent for the data access.
  • Extract the consent token from the response by calling”WindowsLiveLogin” class “ProcessConsent” method.
  • Screen shot for the Concent:

    ConsentToken from Microsoft

    Get Hotmail Contacts

    Now comes the final process for which the blog has been created. Getting the Hotmail contacts.

      1. Create a HttpWebRequest with the below URL
    • HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format(“https://livecontacts.services.live.com/users/@[email protected]{0}/rest/livecontacts”, intlid)); //intlid refers to LocationId
    • request.Headers.Add(“Authorization”, “DelegatedToken dt=\”” + token + “\”“); //token refers to Delegation Token.
  • Get the ResponseStream into the StreamReader in the form of XML.
  • There are couple of handy links which you can use:
    1. Manage registered applications: Click Here
    2. Delegated Authentication Error Codes: Click Here
    3. Manage you shared information. You can revoke access to this information at any time using: Click Here
    4. Link to the source code: Click Here
    Hope the article would be helpful!!! 🙂


    Umesh Mehra

    Lead Engineer, Global Logic, Noida, India

    More Posts