Version 2020

Customize the Login process for iOS

Library Mobile SDK for iOS Login APIs allow you to insert custom logic at different points during the login process and pass custom login parameters in login requests. See KB484291 for a demo of this functionality.

Add custom logic to the login process

You can add custom logic to the login process by creating a class that conforms to LoginDelegate protocol and adding your own logic in corresponding methods. Here are the methods of the LoginDelegate protocol:

Return Type

Method and Description

optional void

loginButtonTapped(loginViewController: UIViewController, loginType: EnumLoginTypes, completionHandler: @escaping ()->Void)

@param loginViewController The login viewController that holds the login button.

@param loginType The login type of the button. SeeCustomize the Login screen for iOS for more information.

@param completionHandler Always call this block once you have completed your work to let the app continue,

Called when login button is tapped.

optional void

handlePreMobileLogin(_ preLoginInfo: [AnyHashable: Any])

@param preLoginInfo Includes information needed for the login request, such as project info, username, and password.

Called before login requests are sent.

optional void

handlePostMobileLogin(_ postLoginInfo: [AnyHashable: Any])

@param postLoginInfo If request succeeds, successInfo from mobileLoginDidSucceed. If request fails, failureInfo from mobileLoginDidFail.

Called after the login requests finish.

optional void

mobileLoginDidSucceed(_ successInfo: [AnyHashable: Any])

@param successInfo Includes the sessionID server returns.

Called when login requests succeed.

optional void

mobileLoginDidFail(_ failureInfo: [AnyHashable: Any])

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

Called when login requests fail.

To enable your customized login delegate class, you need to register it in DossierLoginDelegateManager. Methods that you override in the customized login delegate are called during the login process.

Property in DossierLoginDelegateManager:

Modifier and Type

Property and Description

public static

shared: DossierLoginDelegateManager

This is the shared singleton instance of DossierLoginDelegateManager.

public

skipLoginView: Bool

Indicates whether to skip login view for trusted mode when app is launching and session is valid. Default value is false.

public

formChallengeForTrusted: Bool

Indicates whether there is form challenge for trusted mode. Default value is true.

Method in DossierLoginDelegateManager:

Modifier and Type

Method and Description

public void

setCustomizedLoginDelegate(_ delegate: LoginDelegate?)

Set the custom login delegate to the app.

Implement your customized login process

  1. Set up the environment to use the Library Mobile for iOS project. You are using this project as the basis for your customizations.
  2. Create a custom app delegate.
  3. Right-click the MicroStrategy Library folder and choose New File.

  4. Click Swift File and Next.

  5. Give the file a meaningful name, such as customLoginDelegate and click Create.

  6. Navigate to the CustomAppDelegate.swift file you created in step 2. Import the MicroStrategyLibraryMobileSDK module to use LoginDelegate.

  7. In the CustomLoginDelegate.swift file, define a class named CustomLoginDelegate that conforms to LoginDelegate. Add corresponding login methods and your own custom login logic in the methods.

    import Foundation
    import MicroStrategyLibraryMobileSDK
    
    class CustomLoginDelegate: LoginDelegate {
        /**
           Called when login button is tapped.
           @param loginViewController:  The login viewController that holds the login button.
           @param loginType:  The login type of the button.
           @param completionHandler:  Note you should always call this block once you have done your work to let the app continue.
         */
        func loginButtonTapped(loginViewController: UIViewController, loginType: EnumLoginTypes, completionHandler: @escaping () -> Void) {
            
            // Do something when login button is tapped.
            
            completionHandler()
        }
        
        func handlePreMobileLogin(_ preLoginInfo: [AnyHashable : Any]) {
        
            // Do something before login requests being sent.
            
        }
        
        func handlePostMobileLogin(_ postLoginInfo: [AnyHashable : Any]) {
           
            // Do something after the login requests finished.  This function would be called after loginSuccess or loginFail is called.
            
        }
        
        func mobileLoginDidSucceed(_ successInfo: [AnyHashable : Any]) {
            
            // Do something when login requests succeed.
            
        }
       
        func mobileLoginDidFail(_ failureInfo: [AnyHashable : Any]) {
        
            // Do something when login requests failed.
            
        }
    }

  8. Navigate to the CustomAppDelegate swift file created in step 2. Override the applicationDidFinishLaunching() function. Call DossierLoginDelegateManager to register your CustomLoginDelegate instance.

  9. Clean and build your project. Your CustomLoginDelegate is registered before launching the application and your custom login logic is called at the appropriate time during login.

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 requests made from the client to the Library server, while custom login parameters are only included in the authentication request body before being sent to the server. Define and manipulate these custom request parameters via the SDKEnvSettings util singleton class exposed via MSIGeneric.

Get SDKEnvSettings from MSIGeneric:

Return Type

Method and Description

+(SDKEnvSettings*)

getSDKEnvSettings

This method returns the SDKEnvSettings instance.

The following methods are exposed via the SDKEnvSettings class, relating to custom request parameters:

Return Type

Method and Description

-(NSArray *)

getServerParamKeys

This method returns all the custom login parameter keys you have set.

-(NSString*)

getServerParamForKey:(NSString* ) aKey

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

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

-(void)

removeServerParamForKey:(NSString* )aKey

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

Provide a specific custom login parameter key and remove the corresponding item.

-(void)

setServerParam:(NSString* )aValue forKey:(NSString* )aKey

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

@param aValue Value for the customized login parameter key you want to set.

Use this method to insert one item in the custom login parameter dictionary.

-(void)

clearServerParams()

Use this method to clear all custom login parameters.

Examples for passing your custom login parameters

Use the SDKEnvSettings singleton anywhere you want to store or update custom login parameters in your project like this:

MSIGeneric.getSDKEnvSettings()?.setServerParam("testValue", forKey: "testKey")

You can set an extra custom login parameter just before the login request is sent in the CustomLoginDelegate you previously created.