Obtaining user consent (Android)

This topic describes how an Android app requests permission from the user to access data that the user has stored on Microsoft OneDrive.

In this article
Prerequisites
Request initial scopes
Request additional scopes
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.

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

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 use 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 to OneDrive (Android).

Request initial scopes

If you're using Java, you can set the initial scopes in an instance of the login method of the LiveAuthClient class, like this.

Iterable<String> scopes = Arrays.asList("wl.signin", "wl.basic");
this.auth.login(scopes, this);

Request additional scopes

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

public void moreScopes() {        
	auth.login(this, Arrays.asList(new String[] { "wl.basic" }), new LiveAuthListener() {
		public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
			if (status == LiveStatus.CONNECTED) {
				resultTextView.setText("Signed in.");
				client = new LiveConnectClient(session);
			} else {
				resultTextView.setText("Not signed in.");
				client = null;
			}
		}
		public void onAuthError(LiveAuthException exception, Object userState) {
			resultTextView.setText("Error signing in: " + exception.getMessage());        
			client = null;
		}
	});            
}

Get a list of current permissions

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

public void checkPermissions() {
	auth.login(this, Arrays.asList(new String[] { "wl.basic" }), new LiveAuthListener() {
		public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
			if (status == LiveStatus.CONNECTED) {
				resultTextView.setText("Signed in.");
				client = new LiveConnectClient(session);
				String scopes = TextUtils.join(" ", session.getScopes());
				resultTextView.setText("Signed in. Current scopes = " +  scopes );
			} else {
				resultTextView.setText("Not signed in.");
				client = null;
			}
		}
		public void onAuthError(LiveAuthException exception, Object userState) {
			resultTextView.setText("Error signing in: " + exception.getMessage());        
			client = null;
		}
	});
}