OL Blog's profileThe Microsoft Office Liv...BlogLists Tools Help

Blog


    March 28

    The Microsoft Office Live Client Application Connection code sample

    The Microsoft Office Live Developer Platform Team has created some sample code to show how you can use Microsoft Office Live Web services to connect your client-side application to Microsoft Office Live data.

    This code sample takes advantage of the Microsoft Office Live Discovery Web service, Windows Live ID for client applications , and the authentication services provided in the Microsoft System.Net namespace. Once you know how to combine these services, you can provide access to data in an Office Live subscription from your application without requesting additional credential information.

    As an example of accessing Microsoft Office Live data after authentication, the Client Application Connection sample includes code that connects to a Microsoft Office Live server with the user's Windows Live ID credentials to list all documents in one of the user's Microsoft Office Live document libraries.

    Download the sample

    Client Application Connection is provided as sample code. You can copy snippets of this code or duplicate them in your application to help you provide authenticated connections.

    To download the .exe file, go to the Microsoft Download Center.

    ·        Click the .exe file to install the Client Application Connection files to the following location:

    C:\Microsoft Office Live Developer Resources\Client Application Connection Sample

    Authenticate your Client Application Connection

    With Windows Live ID for client applications, your application can access Windows Live ID sites and services, including Microsoft Office Live, using a customized authentication ticket. Let’s say that Dan Park signs in to his Microsoft Office Live account, and then opens your client application.

    The following steps demonstrate how you can authenticate Dan from your client application to allow access to Microsoft Office Live data.

    Step 1. Authenticate Dan’s Windows Live ID account.

    This sample uses the IdentityManager class of Windows Live ID to create an Identity object for the current user and then uses the Authenticate method of this class to authenticate the user’s Windows Live ID account.

               

    IdentityManager identityManager;

    identityManager = IdentityManager.CreateInstance(applicationId,

                      applicationName);

    Identity identity = identityManager.CreateIdentity();

    if (!identity.Authenticate())

    {

         throw new ApplicationException("Unable to authenticate the

                             user’s Windows Live ID account.");

           }

    Step 2. Get the Microsoft Office Live settings needed to generate a Windows Live ID authentication ticket.

    The Client Application Connection code takes advantage of the Microsoft Office Live Discovery Web service to quickly discover the appropriate Live ID settings. First, it accesses the Discovery Web service.

    Discovery discoSvc = new Discovery();

    discoSvc.Url = "https://apis.officelive.com/discoverywebsvc/discovery.asmx";

     

          Next, it gets the Windows Live ID settings for the Microsoft Office Live service.

     

    LiveIDSettings settings = discoSvc.GetLiveIDSettings();

    Step 3. Request Dan’s current Windows Live ID authentication ticket for the Microsoft Office Live service.

    You can use Windows Live ID’s GetTicket method to get the user’s authentication ticket information for the Microsoft Office Live service.

    string ticket = identity.GetTicket(settings.SiteName, settings.Policy, false);
    Step 4. Authenticate Dan for Microsoft Office Live Web requests.

    The class WindowsLiveAuthenticationModule, included in this sample code, handles Windows Live ID authentication for Microsoft Office Live Web requests. This module implements an IAuthenticationModule interface from the Microsoft System.Net namespace.

    This sample code then creates and registers a new authentication module using the Register method of the AuthenticationManager class in the Microsoft System.Net namespace,  passing the ticket obtained in step 3.

     

    WindowsLiveAuthenticationModule authModule;

    authModule = new WindowsLiveAuthenticationModule(ticket);

                AuthenticationManager.Register(authModule);

    Authenticate is the core method for the Client Application Connection sample custom authentication. The following are details of the actual process that triggers the Authenticate method:

    1.      When an Internet resource requests authentication, the System.Net WebRequest.GetResponse method calls the AuthenticationManager.Authenticate method.

    2.      The AuthenticationManager.Authenticate method calls each registered authentication module to find the first module that can respond to the authentication request.

    3.      When a module responds, an Authorization object is returned to the Web request.

     

    This Authorization is the key you need to unlock Dan’s Microsoft Office Live data.

    Access Microsoft Office Live data

     

    The example in this code is designed to print the names of the documents in the user’s Microsoft Office Live document library if the user is authenticated.

    You can use methods of the Discovery class in the Discovery Web service to determine the subscriptions that are associated with Dan Park and find a document library included in those subscriptions. The GetSubscriptions method allows you to identify a Microsoft Office Live subscription that Dan owns. The GetResources method returns a list of resources, including document libraries, in the subscription. The code in this example selects the first document library it finds.

    The calls to the methods of the Discovery class invoke a WindowsLiveAuthenticationModule to authenticate this Microsoft Office Live Web request:

    discoSvc.UserAgent = discoSvc.UserAgent + ";" + WindowsLiveAuthenticationModule.WindowsLiveClientHeader;

    discoSvc.Credentials = new NetworkCredential();

    To access Windows Live ID sites and services, including Microsoft Office Live, you must find the URL of the Web Service Description Language (WSDL) file that describes the service. The service being used in this example is the SharePoint Lists Web service. In addition to adding this service as a Web reference, the example constructs a URL for it.

    string listServiceUrl = userDocumentLibraryUrl +

                            SharepointServicesPrefix  + "Lists.asmx";

     

    It then connects to the Lists Web service for Dan’s document library.

     

    Lists listsWebService = new Lists();

    listsWebService.Url = listServiceUrl;

     

    Next, it invokes a WindowsLiveAuthenticationModule to authenticate this Microsoft Office Live Web request.

              

    listsWebService.UserAgent = listsWebService.UserAgent + ";" +

              WindowsLiveAuthenticationModule.WindowsLiveClientHeader;

    listsWebService.Credentials = new NetworkCredential();                

    The example then uses the Lists Web service to access and print the titles of all documents contained in Dan’s document library.

    Connect your client applications

    The Web services provided by Microsoft Office Live, Windows Live ID for client applications, and the Microsoft System.Net namespace combine to provide easy access to the information you need in order to provide a connection between a client application and Microsoft Office Live data. You can use the code in this sample to help incorporate this functionality in your application.

     

    The Office Live Developer Platform team

    Comments (3)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    OL Blog has turned off comments on this page.
    Picture of Anonymous
    Christopher wrote:
    In the example above you use the Discovery web service to find the users LiveIDSettings. Is this apis site a general LiveSite that all users can access, or would I have to know the URL of my users site to access this webservice call(Example: https://myUser.Office.Live.com/...)?
    discoSvc.Url = "https://apis.officelive.com/discoverywebsvc/discovery.asmx";
    June 11
    Picture of Anonymous
    Filiberto_Selvas wrote:
    Visit our community to find the answer to this question: www.officelivecommunity.com
    Apr. 2
    Picture of Anonymous
    dodson online wrote:
    hi, can I put 'IFrames' on my Office LIVE Basics website, if so, how? HELP!
    Mar. 31

    Trackbacks

    The trackback URL for this entry is:
    http://officeliveblog.spaces.live.com/blog/cns!7A0018FE70A946FB!626.trak
    Weblogs that reference this entry
    • None