Microsoft Developer Network >
Forums Home
>
Windows Live Developer Forums Forums
>
Windows Live Messenger Web APIs: Development
>
Accessing Live Messenger user profile with minimum effort
Accessing Live Messenger user profile with minimum effort
- Hello all,On my webpage, I need to get the Live ID (the email used in Live Messenger) of a logged in user. I also need to add a conact to that user's contact list. How do I do this with minumum effort? Do I have to use the Windows Live Library and go through all the hoops with consent tokens etc? I cannot use the msnim:add?contact= hyperlink as I need this to work on all browsers.Best regards/Arlaharen
Answers
Hello Arlaharen,
First of all, whatever approach you use, you always have to use Windows Live ID Delegated Authentication (which implies using delegation and consent tokens). Secondly depending on the type of contact you want to add, you may have several choices:
- If you want to add a contact (like a chatbot) to the user's list to allow the user to chat with it, you can use some of the Windows Live Messenger UI Controls. In this case the Sign-In Control (to sign-in users to the Messenger service) and the Add Contact Control (to add the contact to the user's list). The Messenger UI Controls are built on top of the Messenger Library, are rendered on the client side, and only require a small amount of extra code as listed on MSDN here.
To deal with authentication, you need to add a page that retrieves a delegation token from a consent token and refreshes a delegation token on expiration. A sample implementation of this page can be found on MSDN here. - If you want to add a contact to the user's address book instead (if there is no need for IM), you can use the Windows Live Contacts API. This API allows you to send a REST request from server-side in order to add the contact. This method uses Delegated Authentication as well, but requires you to write more code to handle the authentication and to send the REST request.
- If you want to add a contact (like a chatbot) to the user's list to allow the user to chat with it, you can use some of the Windows Live Messenger UI Controls. In this case the Sign-In Control (to sign-in users to the Messenger service) and the Add Contact Control (to add the contact to the user's list). The Messenger UI Controls are built on top of the Messenger Library, are rendered on the client side, and only require a small amount of extra code as listed on MSDN here.
To answer your questions:
- That is correct.
- That should work as long as you call the onGetDelegationToken function with the right value.
The page that receives your AJAX call should decrypt the received value by using the Windows Live ID Delegated Authentication SDK (the Messenger Web Toolkit sample includes this SDK as well). Alternatively, you can use the Microsoft.Samples.Web.MessengerWebToolkit.WindowsLiveMessenger.DecodeToken function from the Messenger Web Toolkit sample code which you can find here (see Step 2). You can find that function in the zip-file under \WebToolkit\MakeYourWebSiteSocial\code\CSharp\MessengerWebToolkit\WindowsLiveMessenger.cs.
- Marked As Answer byArlaharen Wednesday, October 21, 2009 7:56 AM
All Replies
Hello Arlaharen,
First of all, whatever approach you use, you always have to use Windows Live ID Delegated Authentication (which implies using delegation and consent tokens). Secondly depending on the type of contact you want to add, you may have several choices:
- If you want to add a contact (like a chatbot) to the user's list to allow the user to chat with it, you can use some of the Windows Live Messenger UI Controls. In this case the Sign-In Control (to sign-in users to the Messenger service) and the Add Contact Control (to add the contact to the user's list). The Messenger UI Controls are built on top of the Messenger Library, are rendered on the client side, and only require a small amount of extra code as listed on MSDN here.
To deal with authentication, you need to add a page that retrieves a delegation token from a consent token and refreshes a delegation token on expiration. A sample implementation of this page can be found on MSDN here. - If you want to add a contact to the user's address book instead (if there is no need for IM), you can use the Windows Live Contacts API. This API allows you to send a REST request from server-side in order to add the contact. This method uses Delegated Authentication as well, but requires you to write more code to handle the authentication and to send the REST request.
- If you want to add a contact (like a chatbot) to the user's list to allow the user to chat with it, you can use some of the Windows Live Messenger UI Controls. In this case the Sign-In Control (to sign-in users to the Messenger service) and the Add Contact Control (to add the contact to the user's list). The Messenger UI Controls are built on top of the Messenger Library, are rendered on the client side, and only require a small amount of extra code as listed on MSDN here.
- Hi ChrisW_!Thanks for your quick and helpful reply.I have two followup questions;1. In regards to adding the contact, what I want to do is add a contact with the contact's e-mail address used in Live Messenger (username?). In other words; if a user is signed in and authenticated towards Live Messenger via my Page, he can add any contact he knows the username of to his contact list by clicking on a button. Am I right to assume this falls under the first choice you mentioned?2. Since I started this thread, I began going through the process of using Delegated Authentication to accomplish my task. I am currently stuck at the stage where I need to decode the user's consent token and retrieve a delegation token. I tried doing this with an AJAX call like in the code example below. Is this the correct procedure? I'm having trouble finding out what I need to do on the server side to get the delegation token.(Javascript)//Create the consentCompleted function to define a delegate that handles the consentCompleted event.//At this point, the user has provided consent. However, the user is not authenticated or online. The application must use server-side code to decrypt the delegation token by using the consent token.function consentCompleted(sender, e) {var consentToken = e.get_consentToken();// An application must now pass the consent token to its servers where it can// decrypt the token and extract the user's delegation token.getDelegationToken(consentToken, onGetDelegationToken);}function getDelegationToken(consentToken, callback) {// Send the consent token to the application servers in order to decrypt// and return the user's delegation token.//AJAX call to get the delegation token from the consent tokenMyApp.microsoft.livemessenger.liveForms.getDelegationToken(consentToken, callback);}//Create the onGetDelegationToken function to authenticate the user after the delegation token has been retrieved from the server.function onGetDelegationToken(delegationToken) {_identity = new Microsoft.Live.Messenger.DelegatedAuthIdentity(delegationToken);_identity.add_authenticationCompleted(onAuthCompleted);}
To answer your questions:
- That is correct.
- That should work as long as you call the onGetDelegationToken function with the right value.
The page that receives your AJAX call should decrypt the received value by using the Windows Live ID Delegated Authentication SDK (the Messenger Web Toolkit sample includes this SDK as well). Alternatively, you can use the Microsoft.Samples.Web.MessengerWebToolkit.WindowsLiveMessenger.DecodeToken function from the Messenger Web Toolkit sample code which you can find here (see Step 2). You can find that function in the zip-file under \WebToolkit\MakeYourWebSiteSocial\code\CSharp\MessengerWebToolkit\WindowsLiveMessenger.cs.
- Marked As Answer byArlaharen Wednesday, October 21, 2009 7:56 AM
- Thanks ChrisW_, I will check the samples you mentioned. I appreciate your help very much!
/Arlaharen

