Export (0) Print
Expand All

Running the Java Samples for Delegated Authentication

Cc287672.note(en-us,MSDN.10).gifNote:
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.

This topic explains how to install, run, and extend the sample provided in the Java programming language.

Cc287672.note(en-us,MSDN.10).gifImportant:
The Java samples are preconfigured to use default values for the policy URL and return URL parameters. You must update these parameters before you can use the samples. For more information about how to update these parameters, see "Configuring the Samples" later in this topic.

When you install the samples, you put their files in the correct locations on your Web server. In this discussion, we assume that you have direct access to your Web server and that you develop and browse your site from the server.

Cc287672.note(en-us,MSDN.10).gifImportant:
To run these samples, you must install Java Platform, Enterprise Edition, version 5.0 or later.

To install the sample

  1. Make sure that Java Platform, Enterprise Edition (J2EE) with the Java Development Kit (JDK) is installed from the Sun Developer Network (http://java.sun.com).
  2. For purposes of this sample we assume that Java EE was installed with mostly default options, so that the server will be running on port 8080.
  3. Unzip the delauth-java-1.2.zip package and go to the delauth-java-1.2 directory.
  4. Modify BuildAndDeploy.cmd to suit your system settings. This file enables you to indicate where the various Java components are installed on your system.
  5. Run BuildAndDeploy.cmd.

The Java samples are installed. The Java library, named WindowsLiveLogin.java, contains functions shared by both samples.

Cc287672.note(en-us,MSDN.10).gifImportant:
Included in the samples are files named DelAuth-Sample1.xml and DelAuth-Sample2.xml. Make sure that the folder that contains these files cannot be accessed from the Internet, because the files contain important confidential information.

The samples require some configuration changes before you can run them. The following steps describe how to update the configuration files included with the samples.

To configure the samples

Cc287672.note(en-us,MSDN.10).gifImportant:
You must register your application with Microsoft before you run the samples, so that they can access the Windows Live ID service.
  1. Register your application and obtain a client ID. For more information about registering an application, see Getting Your Client ID for Delegated Authentication.
    Cc287672.note(en-us,MSDN.10).gifNote:
    You need both the secret key and the client ID, supplied to you after registration, to complete the configuration process for both samples.
  2. Use a text editor to open the sample files DelAuth-Sample1.xml and DelAuth-Sample2.xml. These files are located in C:\Inetpub\wwwroot\delauth\sampleX, where X is the sample number.
  3. In the appID element, specify the client ID you received while registering the application. The following example illustrates the resulting element.
    <appid>0016000080000709</appid>
    
  4. In the secret element, specify the secret key you established while registering the application. The following example illustrates the resulting element.
    <secret>S!tr0ngPa55worD</secret>
    
  5. For the first sample, in the returnurl element, specify the return URL for the sample. The value for the first sample should be set to the following.
    <returnurl>http://<YourServerHostName>/delauth/sample1/delauth-handler.jsp</returnurl>
    
    The second sample uses the return URL you specified when registering your application. You cannot override the return URL for the second sample.
  6. In the policyurl element, specify the privacy policy URL for the sample. The value for the first sample should be set to the following.
    <policyurl>http://<YourServerHostName>/delauth/sample1/policy.html</policyurl>
    
    The value for the second sample should be set to the following.
    <policyurl>http://<YourServerHostName>/delauth/sample2/policy.html</policyurl>
    
  7. Save and close the sample configuration files.

After you install the samples, you can run them to see a demonstration of how Windows Live ID Delegated Authentication works.

The first sample demonstrates how to use the GetConsentUrl, ProcessConsent, and ProcessConsentToken functions (included in the Java library) to request, process, and parse a consent token from the Windows Live ID consent service.

To run the first sample

  1. Go to http://<YourServerHostName>:8080/delauth/sample1/.
  2. Click click here. You are redirected to the consent-request URL for the Windows Live ID consent service.
  3. If you have not yet signed in to the Windows Live ID service, click Sign in. You are redirected to the Windows Live ID sign-in page.
  4. Type your valid Windows Live ID and password to sign in. After you have signed in, the Windows Live ID consent service attempts to retrieve a consent token and redirects you to the sample application's handler page.
  5. The sample application's handler page redirects you to the sample application's default page.
  6. If a consent token is successfully retrieved, the sample application's default page processes the consent token, stores it in a cookie, and displays the various elements contained within the consent token, as well as the entire consent token.
  7. Click here on the sample application's default page to delete the consent token. You are redirected to the consent application's handler page, where the cookie is expired.

The second sample demonstrates how to combine Web Authentication and Delegated Authentication functionality to sign in a Windows Live ID user; request, process, and parse a consent token from the Windows Live ID consent service; and then sign the user out.

Cc287672.note(en-us,MSDN.10).gifNote:
This sample uses a number of Java library functions and handling techniques intended for Web Authentication purposes. For more information about those functions and techniques, see Using Web Authentication in the Windows Live ID Web Authentication SDK.

To run the second sample

  1. Go to http://<YourServerHostName>:8080/delauth/sample2/.
  2. If the text of the first link on the page is Sign in, click Sign in. You are redirected to the Windows Live ID sign-in page.
  3. Type your valid Windows Live ID and password to sign in. You are redirected to the sample application's default page. The Sign in link has now changed to Sign out and your user ID is displayed on the sample application's default page.
  4. Click click here. You are redirected to the consent request URL for the Windows Live ID consent service. The Windows Live ID consent service attempts to retrieve a consent token and redirects you to the sample application's handler page.
  5. The sample application's handler page redirects you to the sample application's default page.
  6. If a consent token is successfully retrieved, the sample application's default page displays the various elements contained within the consent token, as well as the entire consent token.
  7. Click Sign out. You are signed out.

Now you're ready to explore ways to develop the sample code further to meet your site's needs.

The first sample requests access to a single, hard-coded permission. You could modify this permission to meet your needs, or replace the hard-coded permission with a text box to test access to the various offers and actions defined by a resource provider. The second sample builds on the first sample and provides a more complete example of integrating Web Authentication and Delegated Authentication together on your Web site.

Both samples focus on sending a single offer/action to a resource provider. You can extend these samples to handle multiple offer/actions. To accomplish this, separate each offer/action with a comma. For more information about how to build the consent request that sends these offer/actions, see Requesting Consent.

Look through the Java library to see what additional functionality is available to you. The Java library provides several functions that make it easier to integrate Web Authentication and Delegated Authentication into your Web site, and you can expand the library as needed to suit the requirements of your site.

Finally, you can share your discoveries and learn from others by participating in the Windows Live ID Development Forum.

Other Resources

Live Connect

Show:
© 2014 Microsoft