I have implemented a client-side function called login in my IBM MobileFirst application, which I found on this informative link.
login: function (username,password){
//promise
var logindef = $q.defer();
//tempuser
tempUser = {username:username, password:password};
userObj.username = username;
checkOnline().then(function (onl){
if (onl){ //online
console.log("attempting online login");
var parameters={
'username':'username',
'password':'password'
};
var options = {
parameters:parameters,
adapter:"realmAuth",
procedure:"submitLogin"
};
ch.submitAdapterAuthentication(options,{
onSuccess: function(){
console.log("-> submitAdapterAuthentication onSuccess!");
//update user info, as somehow isUserAuthenticated returns false without it
WL.Client.updateUserInfo({onSuccess: function(){
//return promise
logindef.resolve(true);
}});
}
});
} else { //offline
console.log("attempting offline login");
logindef.resolve(offlineLogin());
}
});
return logindef.promise;
},
I am trying to invoke an adapter function named submitLogin
function submitLogin(parameters){
if (!parameters)
return { 'isSuccessful': false, 'errorMsg' : 'parameters is ' + parameters};
var role="";
if (parameters.username=='admin')
role='admin';
else
role='customer';
var input = {
method : 'post',
returnedContentType : 'plain',
path : 'rest/default/V1/integration/' + role + '/token'+
'?username='+parameters.username+
'&password='+parameters.password,
headers: {"Accept":"application\/json"}
};
var response = WL.Server.invokeHttp(input);
var token=response.text;
token = token.replace("\"", ""); //delete the ""
token = token.replace("\"", "");//*/
//token exp: l9ea4tv62mbfy7kmt0ekv6vdxmb23gjp
if (token!=null)
{
var userIdentity = {
userId: parameters.username,
displayName: parameters.username,
attributes: {
foo: "bar"
}
};
WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);
return {
authRequired: true
};
}
return onAuthRequired(null, "Invalid login credentials");
}
When attempting to execute my application in a browser, I encounter the following error:
[ERROR ] FWLSE0013E: Cannot invoke procedure realmAuth/submitLogin [project Eticket] com.ibm.json.java.JSONObject cannot be cast to com.ibm.json.java.JSONArray