WLClient
This collection of topics lists the public methods of the IBM® MobileFirst® runtime client API for mobile apps, desktop, and web. WL.Client is a JavaScript client library that provides access to IBM MobileFirst capabilities. You can use WL.Client to perform the following types of functions:
Method Summary
Public Methods | ||
public |
addGlobalHeader(name: string, value: string) Adds a HTTP header to all requests made by the MobileFirst SDK. |
|
public |
async getDeviceDisplayName(): Promise<string> Gets the display name of the device. |
|
public |
async getServerUrl(): Promise<string> Returns the current MobileFirst Platform server URL. |
|
public |
pinTrustedCertificatesPublicKey(certificateFileNames: string[]) Pins the host X509 certificate public key to the client application. |
|
public |
registerChallengeHandler(challengeHandlerClass: ChallengeHandler, securityCheckName: string) Register a challenge handler to handle act upon challenges provided for a given security check. |
|
public |
async setDeviceDisplayName(deviceDisplayName: string): * Sets the friendly name of the device. |
|
public |
setHeartbeatInterval(heartbeatIntervalInSeconds: number) The number of seconds between which a heartbeat request is sent to the MobileFirst server to keep the connection alive. |
|
public |
setServerUrl(serverUrl: string) |
|
public |
submitChallengeAnswer(securityCheckName: string, answer: object) Send an answer back to the security check that triggered this challenge. |
Public Methods
public addGlobalHeader(name: string, value: string) source
Adds a HTTP header to all requests made by the MobileFirst SDK. Use the WLClient.removeGlobalHeader API to stop adding the header to further requests
public async getDeviceDisplayName(): Promise<string> source
Gets the display name of the device. The display name is retrieved from the MobileFirst Server registration data. You can see the device display name in the Devices section of the MobileFirst Console.
public async getServerUrl(): Promise<string> source
Returns the current MobileFirst Platform server URL. You can define the server URL in the mfpclient.properties (Android) / mfpclient.plist (iOS) or by calling the WLClient.setServerUrl API
public pinTrustedCertificatesPublicKey(certificateFileNames: string[]) source
Pins the host X509 certificate public key to the client application. Secured calls to the pinned remote host will be checked for a public key match. Secured calls to other hosts containing other certificates will be rejected. Some mobile operating systems might cache the certificate validation check results. Your app must call the certificate pinning method before making a secured request. Calling this method a second time overrides any previous pinning operation. The certificates must be in DER format. When multiple certificates are pinned, a secured call is checked for a match with any one of the certificates.
Params:
Name | Type | Attribute | Description |
certificateFileNames | string[] | The list of paths to the certificate files. On Android this will be under the assets folder. |
public registerChallengeHandler(challengeHandlerClass: ChallengeHandler, securityCheckName: string) source
Register a challenge handler to handle act upon challenges provided for a given security check.
Params:
Name | Type | Attribute | Description |
challengeHandlerClass | ChallengeHandler | The challenge handler object implementing the methods of a SecurityCheck Challenge handler |
|
securityCheckName | string | The name of the security check for which this challenge handler must respond. |
Example:
class UserLoginCH {
constructor() {}
handleChallenge(params){
// Gather credentials from the user
WLClient.submitChallengeAnswer (securityCheck, credentials);
}
handleSuccess(){
// Handle success. Perhaps show a success message or do nothing.
}
handleFailure(){
// Handle failure. Perhaps, show a failure message or ask for credentials again.
}
}
var userLoginCH = new UserLoginCH();
WLClient.registerChallengeHandler(userLoginCH ,"UserLogin") ;
public async setDeviceDisplayName(deviceDisplayName: string): * source
Sets the friendly name of the device. You can see the device display name in the Devices section of the MobileFirst console.
Params:
Name | Type | Attribute | Description |
deviceDisplayName | string | The friendly name to be set for the device. |
Return:
* |
public setHeartbeatInterval(heartbeatIntervalInSeconds: number) source
The number of seconds between which a heartbeat request is sent to the MobileFirst server to keep the connection alive. The default interval is 7 minutes or 420 seconds. Heartbeats are sent only when the app is in the foreground.
Params:
Name | Type | Attribute | Description |
heartbeatIntervalInSeconds | number | Heartbeat interval value in seconds |
public setServerUrl(serverUrl: string) source
Params:
Name | Type | Attribute | Description |
serverUrl | string | The URL of the MobileFirst Platform server to point to. |
Example:
var newserverurl = 'https://mobilefoundation-newserver.mybluemix.net:443/mfp' ;
WLClient.setServerUrl(newserverurl);
public submitChallengeAnswer(securityCheckName: string, answer: object) source
Send an answer back to the security check that triggered this challenge. The answer should be in a JSON format.
Params:
Name | Type | Attribute | Description |
securityCheckName | string | The security check name that represents the challenge. Used to identify which security check requires authentication. |
|
answer | object | The challenge answer to be returned to the server. For example, this could be credentials collected from the user. |