Obtaining user consent (Windows Runtime apps using C#/VB and XAML)

This topic describes how Windows Runtime app using C#/VB and XAML can request permission from the user to access data stored on Microsoft OneDrive.

In this article
Prerequisites
Step 1: Request additional scopes
Step 2: Get a list of current permissions

In order for your app to access a user's data, the signed-in user must consent to letting the app access that data. The Live SDK divides this consent into categories, called scopes. For more info about scopes, see Scopes and permissions.

Some common scopes that your app might want to request are:

  • wl.basic Allows access to a user's basic info.

  • wl.emails Allows access to a user's email addresses.

  • wl.photos Allows access to a OneDrive user's photos.

Note

Initial scopes were requested when the user signed in. We recommend that you limit the number of scopes you request at any given time to the smallest number necessary to perform a task.

If a user chooses to use a feature that requires a scope that your app doesn't currently have permission to access, your app must get consent for the new scope from the user.

The Live SDK uses OAuth 2.0 to enable users to sign in and provide consent to your app. When a user signs in to your app, he or she is redirected to a window that is hosted by the Microsoft account authorization web service.

After the user grants permission to access his or her data, your app can begin working with the user's information.

Prerequisites

The user must be signed in with a Microsoft account. To learn how to sign users in from your app, see Signing users in.

Step 1: Request additional scopes

If the user has not consented to the scopes needed to access specific info, your app can request additional scopes.

private async void btnMoreScopes_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveAuthClient auth = new LiveAuthClient();
        LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });
        if (loginResult.Status == LiveConnectSessionStatus.Connected)
        {
            this.infoTextBlock.Text = "Signed in.";
        }
    }
    catch (LiveAuthException exception)
    {
        this.infoTextBlock.Text = "Error signing in: " + exception.Message;
    }
}

Step 2: Get a list of current permissions

This example returns a list of permissions, representing scopes that the user has already consented to.

private async void btnGetPermissions_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult = await liveClient.GetAsync("me/permissions");
        this.infoTextBlock.Text = operationResult.RawResult;
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error getting permissions: " + exception.Message;
    }
}