Homunculus Reticulli
Homunculus Reticulli

Reputation: 68436

hotmail: user authentication and contact retrieval with PHP

I am trying to write a PHP script that will allow me to do two things:

  1. Allow users to use their Hotmail (I think its called 'Live' now?) account to authenticate themselves to a website

  2. Retrieve an authenticated users contact list from Hotmail.

I have trawled the internet for the past 6 hours, looking for at least a working example that I can modify/extend to do the above two things. There are several dozens similar questions asked here on SO for example - NONE of the proffered answers work any more (admittedly, some of the questions were a few years old).

I tried the Microsoft site and downloaded the latest version of their API which seems to evolve at a rather alarming rate. I finally managed to track down an API which has not been deprecated (yet?).

I followed the instructions and when I attempted to authenticate, I was rewarded with the following mesage, for my efforts:

We're unable to complete your request
Windows Live ID is experiencing technical difficulties. Please try again later.

I immediately tried the online version of the demo and perhaps unsurprisingly, that worked like a charm.

As an aside, I managed to implement the same functionality for Yahoo and GMail, using their OPEN APIs, under an hour each. Now, it is possible that my unmitigated hatred of all things proprietary (sorry make that Microsoft), is causing me to lose the plot a little here.

Has anyone ACTUALLY (in 2012) managed to get a working sample in PHP that allows:

  1. Hotmail (live?) user authentication
  2. Hotmail user contact email retrieval

If you have, a code snippet, or a link to where I can find such a snippet would be very useful, as I have so far, wasted a whole afternoon trying to work the Microsoft Live API via PHP.

PS: No, I'm not interested in OpenInviter, its broken.

Upvotes: 4

Views: 2156

Answers (3)

tanveer javaid
tanveer javaid

Reputation: 131

Please confirm your callback url is with http:// if you only put www.domain.com then get this issue..

Upvotes: 0

mulllhausen
mulllhausen

Reputation: 4435

i wrote my own oauth library based around a single array for each service provider. this array contains all of the data required to perform authentication and retrieve user data. the array i use for msdn (ie. hotmail, outlook, xbox, msn) is:

$msdn = array
(
  'oauth_version'              => '2',
  'oauth_method'               => 'GET',
  'redirect_user_params'       => array
  (
    'url'                      => 'https://oauth.live.com/authorize',
    'response_type'            => 'code',
    'http_params'              => array
   (
     'url',
     'client_id',
     'redirect_uri',
     'response_type',
     'scope',
     'state'
   )
 ),
 'obtain_access_token_params'  => array
 (
   'url'                       => 'https://oauth.live.com/token',
   'grant_type'                => 'authorization_code',
   'http_params'               => array
   (
     'url',
     'client_id',
     'client_secret',
     'code',
     'grant_type',
     'redirect_uri',
     'scope'
    )
  ),
  'scope'                      => 'wl.signin wl.basic',
  'obtain_user_data_params'    => array
  (
    'url'                      => 'https://apis.live.net/v5.0/me',
    'http_params'              => array
    (
      'url',
      'access_token',
      'scope'
    )
  ),
  'client_id'                  => 'xxxxx', // = oauth_consumer_key in oauth 1.0 lingo
  'client_secret'              => 'xxxxxxxxxxxxxxx',
  'readme_url'                 => 'http://msdn.microsoft.com/en-us/library/live/hh243647.aspx'
);

the parameters for each of the three oauth stages (ie "redirect user", "obtain access token" and "obtain user data") are in the http_params arrays. in the case of msdn these parameters end up in the query query string of the url that i send out with curl (since msdn only accepts GET, not POST).

i haven't tried retrieving the user's contact address book, but this would just be a case of extending the scope element with whatever extra information you require (documented here http://msdn.microsoft.com/en-us/library/live/hh243646.aspx). as you can see from the http_params arrays, the scope parameter is used in each of the three oauth stages.

Upvotes: 1

Jay Gibb
Jay Gibb

Reputation: 483

Try out a Hotmail/MSN/Live import on the CloudSponge test drive to see if that's the user experience you're hoping for.

If it works for you, you can use our widget or our API. If you want to use the API, we have a PHP wrapper already written for your convenience.

Upvotes: 0

Related Questions