MicroStrategy ONE

Customize the Login Process for Android

Library Mobile SDK for Android login APIs allow you to insert custom logic at different points during the login process and pass custom login parameters in login requests.

Before you get started, set up the environment so that you can use the MicroStrategy Library Mobile project as the base for your customization.

Add Custom Logic to the Login Process

You can add custom logic to the login process by implementing the LoginListener interface, whose methods you call during the login process. Here are the methods of the com.microstrategy.android.infrastructure.login.LoginListener interface.

Return Type

Method and Description

void

beforeLogin(Map<String, Object> info)

@param info Includes information such as project information, user name, and password that are needed for the login request.

Called before login requests are sent.

void

afterLogin(Map<String, Object> info)

@param info Includes info from loginSuccess if the request succeeds or info from loginFailed if the request fails.

Called after the login request finishes.

void

loginSuccess(Map<String, Object> info)

@param info Includes the session ID the server returns.

Called when login requests succeed.

void

loginFailed(Map<String, Object> info)

@param info Includes the reason why the login request fails.

Called when the login requests fail.

void

loginButtonTapped(Activity activity, int loginType, Callback callback)

Called when the login button of a specific auth type if tapped. Usually used to add custom actions before triggering the actual logn process. This method must be implemented when using LoginListener or the login process breaks

@param activity The login dialog activity.

@param login The LoginType of the button being tapped. See Customization of individual login buttons for more information.

@param callback Callback to continue the login. It should be called only once in this method.

To enable custom logic, the implemented LoginListener class needs to be set using the following LoginCustomization method:

Modifier and Return Type

Method and Description

public void

setLoginListener(LoginListener loginListener)

Set the custom login listener to the app.

In addition, the following variables are available in the LoginCustomization instance to determine whether to show or hide login dialogs:

Modifier and Return Type

Method and Description

public void

setSkipLoginView(boolean skipLoginView)

@param skipLoginView If true, when the Intelligence server session is invalid, the app tries to login directly with existing credentials, instead of displaying the login dialog.

public void

setFormChallengeForTrusted(boolean formChallengeForTrusted)

@param formChallengeForTrusted If false, when the Trusted login button is tapped, trusted authentication is performed silently, instead of displaying the Trusted Authentication web view dialog.

Implement your customized login process

  1. Create a new Java class that implements LoginListener. The following code snippet shows an example for a class named MyLoginListener:
  2. Copy
    public class MyLoginListener implements LoginListener {
        @Override
        public void beforeLogin(Map<String, Object> info) {
            // do something before login request is sent
        }

        @Override
        public void afterLogin(Map<String, Object> info) {
            // do something after dealing with login request, this means this function is called after loginSuccess or loginSuccess is called
        }

        @Override
        public void loginSuccess(Map<String, Object> info) {
            // do something after login is success
        }

        @Override
        public void loginFailed(Map<String, Object> info) {
            // do something after login failed
        }

        @Override
        public void loginButtonTapped(Activity activity, int loginType, Callback callback) {
            // Do something when login button of specific auth type is tapped; usually used to add custom actions before the
            // actual login process triggered; this method has to be implemented when using the `LoginListener` or the
            // login process will break.
            callback.onContinue();
        }
    }
  3. Implement AppDelegate according to Customize the App Lifecycle for Android.
  4. Navigate to the customized AppDelegate created in the previous step. Create a listener object from the class created in the first step. Set the listener object to LoginCustomization in the onApplicationWillFinishLaunchingWithIntent(…) function using LoginCustomization.setLoginListener(…).
  5. Copy
    ...
        @Override
        public void onApplicationWillFinishLaunchingWithIntent(Intent intent) {
            ...
            MyLoginListener myLoginListener = new MyLoginListener();
            LoginCustomization.getInstance().setLoginListener(myLoginListener);
            ...
        }
    ...

Pass Custom Login Parameters

You can pass custom information in a login request for authentication purposes. Custom HTTP request parameters and custom HTTP headers can be provided in any request made from the client to the Library sever, while custom login parameters are only included in the authentication request body before being sent to the server. These custom request parameters can be defined and manipulated via the CustomizedLoginParameter util singleton class.

The following methods are exposed via the com.microstrategy.android.model.config.CustomizedLoginParameter class, relating to the custom request parameters:

Return Type

Method and Description

public static CustomizedLoginParameter

sharedCustomizedLoginParameter()

This method returns the singleton of this class

public String[]

getCustomizedLoginParameterKeys()

This method returns all the custom login parameters keys you set.

public String

getCustomizedLoginParameterForKey(String key)

@param key The string of the customized login parameter key.

Provide a specific custom login parameter key and return the value.

public void

removeCustomizedLoginParameterForKey(String key)

@param key The string of the customized login parameter key.

Provide a specific custom login parameter key to remove the item.

public void

setCustomizedLoginParameterForKey(String value, String key)

@param key The string of the customized login parameter key.

@param value The value for the customized login parameter key you want to set.

This method is used to insert one item in the custom login parameter dictionary.

public void

clearCustomizedLoginParameters()

This method is used to clear all custom login parameters.

Examples for Passing Custom Login Parameters

Use the CustomizedLoginParameter singleton instance anywhere you want to store or update custom login parameters in your project.

Copy
CustomizedLoginParameter.sharedCustomizedLoginParameter().setCustomizedLoginParameterForKey("testValue","testKey");

You can add an extra custom login parameter just before the login request is sent in MyLoginListener, which you created in Add Custom Logic to the Login Process.