RIA Services and Windows Live ID

There is a new Authentication Sample that shows how to use RIA Services with Windows Live ID (WLID). It’s a little more complex than the others, so I thought it was worth discussing some of the interesting features.

First, the sample opens another window to prompt for WLID credentials. In some scenarios, it might be more useful to force a user to log on with a WLID before navigating to your site. However, most people prefer being able to login from within the Silverlight application. Since that’s not currently an option when using WLID, opening another window is the next best thing.

The next interesting task is to make the LoginOperation wait until the user actually logged in. My original implementation just polled the server, but that felt a bit like a brute force solution. For my second attempt, I chose to use Silverlight’s local messaging.

  1. When the login operation starts, it opens a window and begins listening for a local message.
  2. Once the user logs in, the WLID window will redirect to a page that starts a different Silverlight application.
  3. That application sends a local message that says “Hey. I’m done.” and then closes the window.
  4. The first Silverlight application receives the message, queries the server for the updated data, and then completes the operation.

At this point, we’ve exhausted most of what’s in the sample. It’s worth noting a couple other things that you’d probably be interested in including in a real application. First, WLID web authentication is useful, but you might be interested in accessing properties from the user’s live account. For that you’d want to look at delegated authentication. Second, you’d want some way to integrate the user’s Live ID into your application. This likely means using the wllUser.Id value (see the AuthenticationService in the sample) as the primary key in you user database.