Authorization documentation

This section covers the authorization project features of the SDK. Authentication is the process of verifying who a user is, while authorization is the process of verifying what they have access to.

Starting authorization requests

The authorization request is started with the following code sample which launches an Activity to present the login screen to the user for authentication.

Intent authIntent = Data4LifeClient.getInstance().getLoginIntent(MainActivity.this, null);
startActivityForResult(authIntent, requestCode);

You can pass along optional scopes, otherwise the SDK uses the default scopes for the authorization request.

Ending authorization requests

Once the user is logged in, canceled the authorization request, or if an exception occured during the authentication process, the SDK sends the response to the integrator application in the onActivityResult(…) method. The authorization results can be the following:

  • Activity.RESULT_OK – when the login is successful.

  • Activity.RESULT_CANCELED – when the login fails, with additional payload in data, as shown in the example.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == GC_AUTH) {
        if (resultCode == RESULT_OK) {
            loggedIn();
        } else if (data.getExtras() != null) {
            if (data.getExtras().containsKey("error")) {
                Snackbar.make(mRootCL, "Failed to log in to data4life", Snackbar.LENGTH_SHORT).show();
            } else if (data.getExtras().containsKey("canceled")) {
                Snackbar.make(mRootCL, "User canceled authorization request", Snackbar.LENGTH_SHORT).show();
            }
        }
    }
}

With your consent, we will analyze your behaviour on the website to improve the website for all users. If you consent to the transmission of analysis data, click “Accept”. You can use the website without giving consent to analyze your behaviour. For further information, visit the privacy policy.