401 Unauthorized when Acquiring an Access Token: Windows Live SDK

Share on:

Working with other people is hard. Working with new SDK documentation is even harder, especially when it’s wrong.

If you’re following the Working with OAuth WRAP Windows Live SDK documentation and you get to the Acquiring an Access Token sample you’ll probably encounter a 401 unauthorized error when you try and read the response from https://consent.live.com/AccessToken.aspx. This is because the POST data that the sample code gets you to build up is incorrect.

Instead of:

 1
 2string postData = string.Format(
 3    "{0}?wrap_client_id={1}&wrap_client_secret={2}&wrap_callback={3}&
 4     wrap_verification_code={4}&idtype={5}",
 5    requestUrl,
 6    appSettings["wll_appid"],
 7    appSettings["wll_secret"],
 8    "http://www.fabrikam.com",
 9    verificationCode,
10    "CID");

Use this:

1
2string postData = string.Format(
3    "wrap_client_id={0}&wrap_client_secret={1}&wrap_callback={2}&
4     wrap_verification_code={3}&idtype={4}",
5    appSettings["wll_appid"],
6    appSettings["wll_secret"],
7    "http://www.fabrikam.com",
8    verificationCode,
9    "CID");

For some reason the sample code was including the URL the request was going to in the post data, which confuses the server into thinking that no wrap_client_id has been posted.

Hope that helps.