This topic shows you how to use Live Connect single sign-on to authenticate users in Azure Mobile Services from a Windows Store or Windows Phone 8.1 Store app. In this tutorial, you add authentication to the quickstart project using Live Connect. When successfully authenticated by Live Connect, a logged-in user is welcomed by name and the user ID value is displayed.

NOTE:

This tutorial demonstrates the benefits of using the single sign-on experience provided by Live Connect for Windows Store apps. This enables you to more easily authenticate an already logged-on user with you mobile service. For a more generalized authentication experience that supports multiple authentication providers, see the topic Get started with authentication.

This tutorial walks you through these basic steps to enable Live Connect authentication:

This creates a member variable for storing the current Live Connect session and a method to handle the authentication process. This code forces a logout, when possible, to make sure that the user is prompted for credentials each time the application runs. This makes it easier to test the application with different Microsoft Accounts to ensure that the authentication is working correctly. This mechanism will only work if the logged in user does not have a connected Microsoft account.

NOTE:

You should not request either Live Connection authentiction tokens or Mobile Services authorization tokens every time that your app runs. Not only is this inefficient, you can run into usage-relates issues should many customers try to start your app at the same time. A better approach is to cache the tokens and first try to use the cached Mobile Services token before calling LoginWithMicrosoftAccountAsync. For an example of how to cache this token, see Get started with authentication

Update string << INSERT REDIRECT DOMAIN HERE >> from the previous step with the redirect domain that was specified when configuring the app in Live Connect, in the format https://service-name.azure-mobile.net/.

NOTE:

In a Windows Store app, an instance of the LiveAuthClient class is created by passing the redirect domain URI value to the class constructor. In a Windows Phone 8 app, the same class is instantiated by passing the client ID.

Replace the existing OnNavigatedTo event handler with the handler that calls the new Authenticate method: