Search code examples
ibm-mobilefirstworklight-adaptersworklight-security

How can use web services to validate username and password in worklight Adapter based authentication?


singleStepAuthRealmChallengeHandler.handleChallenge = function(response){
var authRequired = response.responseJSON.authRequired;
user_id=response.responseJSON.loginUser;
if (authRequired == true){
    $("#AppDiv").hide();
    $("#AuthDiv").show();
    $("#AuthPassword").empty();
    $("#AuthInfo").empty();
   if (response.responseJSON.errorMessage){
        $("#AuthInfo").html(response.responseJSON.errorMessage);
   }

} else if (authRequired == false){

$('#AuthSubmitButton').attr('href','home.html');
    $("#AuthSubmitButton").click();
    $("#AuthSubmitButton").click();
    singleStepAuthRealmChallengeHandler.submitSuccess();
}};
$("#AuthSubmitButton").bind('click', function () {
var username = $("#AuthUsername").val();
var password = $("#AuthPassword").val();

var invocationData = {
    adapter : "SingleStepAuthAdapter",
    procedure : "verifyLogin",
    parameters : [ username, password ]
};

var options= {
        onSuccess: success,
        onFailure: failure`enter code here`
};
WL.Client.invokeProcedure(invocationData, options);});
function success(response)
{
var result=JSON.stringify(response);
var invocationData = {
        adapter : "SingleStepAuthAdapter",
        procedure : "submitAuthentication",
        parameters : [ result ]
    };
singleStepAuthRealmChallengeHandler.submitAdapterAuthentication(invocationData, {});}

Is this method correct ???? Its not working when i user is logged in doesn't redirects to home page. :-(

Here first I m trying to invoke procedure get the username password from server and in success function i am calling submit authentication but when the user logged in, next time when i access the secure procedure it doesn't redirects directly to home page instead of that it says user already logged in it suppose to run get authrequired = false and goto home page.

I am using rest api's to get the username and password and passing to submitauthentication function.

Is it because invoking twice there is a problem i cant just figure it out please help.


Solution

  • I validated the Username Password on Server Side itself referred Mashup of Adapters.You can refer this link Mashup