Preparing the Kapsel Application for Afaria Provisioning

To prepare the Kapsel application to be provisioned through Afaria, provide an initial context to the Login plugin, and specify an application ID configured on SAP Mobile Platform Server with an X.509 security profile.

Specify information needed for provisioning in these files:

Create an index.html which specifies an application ID that is configured on SAP Mobile Platform Server with a security profile for X.509 authentication. The following is a sample index.html:
<html>
    <head>
        <script src="datajs-1.1.1beta2.js"></script>
        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
        <script>
            applicationContext = null;
            var appId = "certAuth"; // Change this to app id on server
            
            function init() {
                
                // Optional initial connection context
                var context = {
                    "serverHost": "example.corp", //Place your SMP 3.0 server name here
                    "https": "false",
                    "serverPort": "8080",
                    "user": "username", //Place your user name for the OData Endpoint here
                    "password": "xxxxxxx",  //Place your password for the OData Endpoint here
                    "communicatorId": "REST",
                    "passcode": "password",
                    "unlockPasscode": "password"
                };
                sap.Logon.init(logonSuccessCallback, errorCallback, appId, context, sap.logon.IabUi);
                console.log("init completed");
            }
        
            function read() {
                var url = applicationContext.applicationEndpointURL;
				var logonCert = new sap.AuthProxy.CertificateFromLogonManager(appId);
				var headers = {};
				headers["X-SMP-APPCID"]=applicationContext.applicationConnectionId;
				var errorCB = function(errorInfo){
					alert("error: " + JSON.stringify(errorInfo));
				}
				var successCB = function(result){
					alert("success: " + JSON.stringify(result));
				}
		
				sap.AuthProxy.get(url,headers,successCB,errorCB,null,null,null,logonCert);
            }
            
            function readSuccessCallback(data, response) {
				alert("success: " + JSON.stringify(data));
                /*var carrierTable = document.getElementById("carrierTable");
                
                for (var i = data.results.length -1; i >= 0; i--) {
                    var row = carrierTable.insertRow(1);
                    var cell1 = row.insertCell(0);
                    var cell2 = row.insertCell(1);
                    cell1.innerHTML = data.results[i].carrid;
                    cell2.innerHTML = data.results[i].CARRNAME;
                }*/
            }
            
            function clearTable() {
                var carrierTable = document.getElementById("carrierTable");
                while(carrierTable.rows.length > 1) {
                    carrierTable.deleteRow(1);
                }
            }
            
            function logonSuccessCallback(result) {
                console.log("logonSuccessCallback " + JSON.stringify(result));
                if (result) {  //calling registerOrUnlock returns null the second time it is called.
                    applicationContext = result;
                }
            }
            
            function logonLockSuccessCallback(result) {
                console.log("logonLockSuccessCallback " + JSON.stringify(result));
                applicationContext = null;
            }
            
            function logonUnregisterSuccessCallback(result) {
                console.log("logonUnregisterSuccessCallback " + JSON.stringify(result));
                applicationContext = null;
            }
            
            function register() {
                sap.Logon.registerOrUnlock(logonSuccessCallback, errorCallback);
            }
            
            function unRegister() {
                sap.Logon.core.deleteRegistration(logonUnregisterSuccessCallback, errorCallback);
                clearTable();
            }
            
            function lock() {
            
            function errorCallback(e) {
                alert("An error occurred");
                alert(JSON.stringify(e));
            }
                sap.Logon.lock(logonLockSuccessCallback,errorCallback);
                clearTable();
            }
            
            function unlock() {
                sap.Logon.unlock(logonSuccessCallback,errorCallback);
            }
            
            document.addEventListener("deviceready", init, false);
            
            </script>
        
    </head>
    <body>
        <h1>Logon Sample</h1>
        <button id="register" onclick="register()">Register</button>
        <button id="read" onclick="read()">Read</button>
        <button id="unregister" onclick="unRegister()">Unregister</button>
        <button id="lock" onclick="lock()">Lock</button>
        <button id="unlock" onclick="unlock()">Unlock</button>
        <table id="carrierTable"><tr><th>Carrier ID</th><th>Carrier Name</th></tr></table>
    </body>
</html>