Class: MASPluginMAS

MASPluginMAS

This main class contains the functions for MAS Lifecycle Management.
MASPluginMAS Construtor
var MAS = new MASPlugin.MAS();

Methods

authorize(successHandler, errorHandler, code)

This method is used to authorize the application and user via QRCode session transfer. The user scans and fetches the auth_code from a QRCodeon another device/application and uses this API to send the code to MAG server to authorize the session on another device.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
code string The code extracted by the QRCode scanner
Source:

cancelAuthentication(successHandler, errorHandler)

Cancels the current user's authentication session process. Generally called when Cancel button is clicked on Authentication UI.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

cancelGenerateAndSendOTP(successHandler, errorHandler)

Cancels the current session of OTP Generation process. To be called in scenario when Cancel button is clicked on the OTP Channel Selection screen.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

cancelOTPValidation(successHandler, errorHandler)

Cancels the current OTP validation process of the user. To be called in scenario when Cancel button is clicked on the OTP validation screen.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

completeAuthentication(successHandler, errorHandler, username, password)

Completes the current user's authentication session validation. Similar to the loginWithUsernameAndPassword API but used in case when login is pending due to a previous request in queue.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
username string username of the user.
password string password of the user.
Source:

configFileName(successHandler, errorHandler)

Sets the name of the mobile configuration file. This gives the ability to set the file's name to a custom value.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
fileName. string Must be a JSON file similar to the msso_config.json file.
Source:

deleteFromPath(successHandler, errorHandler, path, parametersInfo, headersInfo, requestType, responseType, isPublic)

Invokes an API on the Gateway using the HTTP DELETE method.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
path string The API path which the user wants to access. For example, /protected/endpoint/score
parametersInfo Object Query Parameters to be passed along with the request.
Example
{
  "x-otp":"2345",
  "empName":"Jon"
}
headersInfo Object The HTTP Headers to be passed along with the request.
Example
{
  "Content-Type":"application/xml",
  "reload-cache":"true"
}
requestType MASPluginConstants.MASRequestResponseType specifies the request type of the request.
responseType MASPluginConstants.MASRequestResponseType specifies the response type of the request
isPublic boolean specifies if the API being called is public or not
Source:

doSocialLogin(successHandler, errorHandler, provider)

The API to perform social login. Based on the provider being selected, it redirects to the login provider's oauth flow and performs Authorization and Authentication for the user.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
provider string An identifier of the social login provider that is defined on MAG server. Values : `google`, `facebook` etc.
Source:

enableBrowserBasedAuthentication(successHandler, errorHandler)

Enables Browser-based authentication i.e. instead of the default login UI, it would redirect to the browser-based UI that is developed and stored on MAG server.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

enableIdTokenValidation(successHandler, errorHandler, enableValidation)

Sets boolean indicator of enforcing id_token validation upon device registration/user authentication.id_token is being validated as part of authentication/registration process against known signing algorithm.
Mobile SDK currently supports following algorithm(s): - HS256
Any other signing algorithm will cause authentication/registration failure due to unknown signing algorithm.
If the server side is configured to return a different or custom algorithm, ensure to disable id_token validation to avoid any failure on Mobile SDK.
By default, id_token validation is enabled and enforced in authentication and/or registration process; it can be opted-out.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
enableValidation boolean BOOLEAN value that indicates whether id_token validation is enabled or not.
Source:

enableJwksPreload(successHandler, errorHandler, enable)

Enable JWKS preloading.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
enable boolean True to enable JWKS preloading. False to disable JWKS preloading. Default value is 'false'
Source:

enablePKCE(successHandler, errorHandler, enable)

Enable PKCE extension to OAuth.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
enable boolean The behaviour of this flag would be
ValueDescription
trueEnable PKCE extension i.e. while authorizing enable PKCE based validation
falseDisable PKCE extension
Source:

gatewayIsReachable(successHandler, errorHandler)

Checks whether the Gateway is reachable or not.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

generateAndSendOTP(successHandler, errorHandler, channels)

Requests server to generate and send OTP to the channels provided.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
channels Array.<string> user defined variable that is an array of channels where the OTP is to be delivered. For example, ['sms','email']
Source:

getFromPath(successHandler, errorHandler, path, parametersInfo, headersInfo, requestType, responseType, isPublic)

Invokes an API on the Gateway using the HTTP GET method.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
path string The API path which the user wants to access. For example, /protected/endpoint/score
parametersInfo Object Query Parameters that is passed along with the request.
Example
{
  "x-otp":"2345",
  "empName":"Jon"
}
headersInfo Object The HTTP Headers that is passed along with the request.
Example
{
  "Content-Type":"application/xml",
  "reload-cache":"true"
}
requestType MASPluginConstants.MASRequestResponseType specifies the request type of the request.
responseType MASPluginConstants.MASRequestResponseType specifies the response type of the request
isPublic boolean specifies if the API being called is public or not
Source:

getMASState(successHandler, errorHandler)

Returns current value of the MASPluginConstants.MASState. The value can be used to determine the current state of the SDK.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

grantFlow(successHandler, errorHandler, MASGrantFlow)

Sets the OAuth grant type property. This should be set before MAS start is called
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
MASGrantFlow MASPluginConstants.MASGrantFlow The desired OAuth Flow to be set for this session.
Source:

initialize(successHandler, errorHandler)

Initializes the MAS plugin. This includes setting of the various listeners that are required for authenticating the user while registration of the application with the Gatewayand accessing various protected API. All other initialization related setting must be done in this method.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

isIdTokenValidationEnabled(successHandler, errorHandler)

Gets boolean indicator of enforcing id_token validation upon device registration/user authentication.id_token is being validated as part of authentication/registration process against known signing algorithm.
Mobile SDK currently supports the HS256 algorithm
Any other signing algorithm will cause authentication/registration failure due to unknown signing algorithm.
If the server side is configured to return a different or custom algorithm, ensure to disable id_token validation to avoid any failure on Mobile SDK.
By default, id_token validation is enabled and enforced in authentication and/or registration process; it can be opted-out.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

isJwksPreloadEnabled(successHandler, errorHandler)

Determines whether preloading of JWKS is enabled.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

isPKCEEnabled(successHandler, errorHandler)

Determines whether PKCE extension is enabled.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

postMultiPartForm(successHandler, errorHandler, path, parametersInfo, headersInfo, requestType, responseType, isPublic, multipartForm, progressListener)

PostMultiPartForm adds the capability to upload multipart forms over HTTP(s) POST to the backend services via Layer7 Gateway.The requestType and responseType are the optional parameters. If the requestType and responseType is not present,then it is set to the Default Type to requestType as "multipart/form-data" and responseType as JSON.
`multipartForm` is the mandatory parameter along with `path`
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
path string path to the url. For example, "/protected/resource/*"
parametersInfo Object Query Parameters to be passed along with the request.
Example
{
  "x-otp":"2345",
  "empName":"Jon"
}
headersInfo Object The HTTP Headers to be passed along with the request.
Example
{
  "Content-Type":"application/xml",
  "reload-cache":"true"
}
requestType MASPluginConstants.MASRequestResponseType specifies the request type of the request.
responseType MASPluginConstants.MASRequestResponseType specifies the response type of the request
isPublic boolean specifies if the API being called is public or not
multipartForm MASPluginMultipartForm Representation of a multipart form. For usage see {MASPluginMultipartForm}
progressListener function A function to listen to form upload progress.
Source:
Example

The progressListener struct should have the below facade.

	function(progress){// This function will be invoked with the progress percent of the data uploaded.
       if(progress == -1){
           // Close the progress bar
       }
       if(progress > 0){
           Update the HTML/jQuery progress bar with the progress percent
       }
    });

postToPath(successHandler, errorHandler, path, parametersInfo, headersInfo, requestType, responseType, isPublic)

postToPath does the HTTP POST call to the Gateway. This expects at least three mandatory parameters as shown in the below example. The requestType and responseType are the optional parameters. If the requestType and responseType is not present, then it is set to the Default Type to JSON.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
path string path to the url. For example, "/protected/resource/*"
parametersInfo Object Query Parameters to be passed along with the request.
Example
{
  "x-otp":"2345",
  "empName":"Jon"
}
headersInfo Object The HTTP Headers to be passed along with the request.
Example
{
  "Content-Type":"application/xml",
  "reload-cache":"true"
}
requestType MASPluginConstants.MASRequestResponseType specifies the request type of the request.
responseType MASPluginConstants.MASRequestResponseType specifies the response type of the request
isPublic boolean specifies if the API being called is public or not
Source:

putToPath(successHandler, errorHandler, path, parametersInfo, headersInfo, requestType, responseType, isPublic)

Invokes an API on the Gateway using the HTTP PUT method.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
path string The API path which the user wants to access. For example, /protected/endpoint/score
parametersInfo Object Query Parameters to be passed along with the request.
Example
{
  "x-otp":"2345",
  "empName":"Jon"
}
headersInfo Object The HTTP Headers to be passed along with the request.
Example
{
  "Content-Type":"application/xml",
  "reload-cache":"true"
}
requestType MASPluginConstants.MASRequestResponseType specifies the request type of the request.
responseType MASPluginConstants.MASRequestResponseType specifies the response type of the request
isPublic boolean specifies if the API being called is public or not
Source:

removeAuthCallbackHandler()

Removes the authentication listener set by developer. This would fallback to thedefault mechanism of Authentication that the CA Mobile Cordova Plugin handles.
Source:

setAuthCallbackHandler(authHandler)

Enables the developer to set its own Authentication Listener or callback handlingmechanism, which overrides the one that the CA Mobile Cordova Plugin sets. The developer needs to set theirbusiness logic such as auditing etc. inside the authHandler function. The developer must call the MAS.completeAuthentication or MAS.cancelAuthentication API from this function to unblock the original API call.
Parameters:
Name Type Description
authHandler function user defined authentication callback handling function
Source:
Example

How the authHandler structure should look like

function(result){
	let requestType = result.requestType;
	console.log(JSON.stringify(result));
	if(requestType !== null && requestType === 'Login'){
		mas.completeAuthentication(
			function () {
				console.log("Login successful");
			},
			function (error) {
				let returnedError = "Internal Server Error";
				if (error!=null && error.errorMessage != null) {
					returnedError = JSON.stringify(error.errorMessage);
				}
				console.log("Error in Login::"+returnedError);
			}, "username", "password");
			// Or you can choose to cancel this request as below
			// mas.cancelAuthentication(function() {},function (){});
		}
}

setCustomLoginPage(successHandler, errorHandler, customPage)

Sets the authentication UI handling page i.e. developer can override the default Authentication UI HTML using this API.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
customPage string user defined page if you want the plugin to use it. "mas-login.html" is the default page.
Source:

setCustomOTPChannelsPage(successHandler, errorHandler, customPage)

Sets the OTP Channels Selection UI handling page i.e. developer can override the default OTP Channel Selection UI HTML using this API.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
customPage string user defined page if you want the plugin to use it. "mas-otpchannel.html" is the default page.
Source:

setCustomOTPPage(successHandler, errorHandler, customPage)

Sets the OTP UI handling page i.e. developer can override the default OTP handling UI HTML using this API.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
customPage string user defined page if you want the plugin to use it. "mas-otp.html" is the default page.
Source:

setSecurityConfiguration(successHandler, errorHandler, masSecurityConfiguration)

Sets the Security Configurations for External Servers. Invoke this API before making calls to external server.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
masSecurityConfiguration Object A JSON representing the MASSecurityConfiguration struct.
Source:
Example

Populates and set the MASSecurityConfiguration object to the MAS Lifecycle

var MAS = new MASPlugin.MAS();var config = new MASPlugin.MASSecurityConfiguration();var publicKeyHash = publicKeyHash; config.setHost("mygw.ca.com");config.setPublic("true");config.addPublicKeyHash("jjHshjkslsk....sjsjjsjs");//server’s public key hashMAS.setSecurityConfiguration(successHandler, errorHandler, config.getSecurityConfiguration());

signWithClaims(successHandler, errorHandler, claims)

Signs MASClaims object with the default private key.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
claims Object claims in the form JSON object
Source:

signWithClaimsPrivateKey(successHandler, errorHandler, claims, privateKey)

Signs MASClaims object with a custom private key.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
claims Object claims in the form JSON object
privateKey string private key as a base64 encoded string
Source:

start(successHandler, errorHandler)

Starts the lifecycle of the MAS processes i.e. Configuration loading, Listeners loading etc.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

startWithDefaultConfiguration(successHandler, errorHandler, defaultConfiguration)

Starts the lifecycle of the MAS processes. This will load the default JSON configuration rather than from the storage.If the SDK is already initialized, this method stops and restarts the SDK.The default JSON configuration file should be msso_config.json. This will ignore the JSON configuration in the keychain storage and replace it with the default configuration.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
defaultConfiguration boolean The behaviour of SDK start would be
ValueDescription
trueThe SDK load the default JSON configuration from msso_config.json packed in the app
falseThe SDK load the stored JSON configuration from local device storage from last run
Source:

startWithJSON(successHandler, errorHandler, jsonObject)

Starts the lifecycle of the MAS processes with a specified JSON.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
jsonObject Object The JSON object similar to msso_config.json content to be used to initialize the MAS SDK.
Source:

startWithURL(successHandler, errorHandler, url)

Starts the lifecycle of the MAS processes with given JSON configuration file path or URL.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
url string URL of the JSON configuration file path
Source:

stop(successHandler, errorHandler)

Stops the lifecycle of all MAS processes.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

useNativeMASUI(successHandler, errorHandler)

Use Native MASUI. By default, CA Mobile Cordova plugin uses the HTML login screen. This API overrides to use the native Mobile SDK UI.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
Source:

validateOTP(successHandler, errorHandler, otp)

Validates the OTP i.e. User needs to validate the OTP via MAG server using this API.
Parameters:
Name Type Description
successHandler successCallbackFunction user defined success callback that is invoked on success scenario.
errorHandler errorCallbackFunction user defined error callback that is invoked on failure scenario.
otp string one-time password that the user receives for validation.
Source: