0
votes

I am trying to execute the sample application given here but facing issues. When I click on the "Get Secret" data button, the request reaches the adapter but I get a failed response as below.

04-29 22:12:22.464: I/chromium(2802): [INFO:CONSOLE(34)] "=======getSecretData_CallbackFail========={"responseHeaders":{"X-Powered-By":"Servlet/3.0","Content-Type":"text/plain; charset=UTF-8","Content-Length":"21","Date":"Sat, 29 Apr 2017 16:41:31 GMT","WWW-Authenticate":"Bearer realm=\"imfAuthentication\", scope=\"AuthRealm\""},"status":401,"responseText":"missing_authorization","errorMsg":"Unauthorized","invocationContext":null}", source: file:///android_asset/www/default/js/main.js (34)

I am testing the application from an Android phone. Can someone suggest what am I doing wrong?

function getSecretData(){
    var resourceRequest = new WLResourceRequest("/adapters/AuthenticationService/getSecretData", WLResourceRequest.GET, 30000);
    resourceRequest.send().then(
        getSecretData_CallbackOK,
        getSecretData_CallbackFail
    );
}

The above code is used at client to invoke the adapter. The onAuthRequired function is called but errormessage is undefined.

function onAuthRequired(headers, errorMessage){
    WL.Logger.info("Authservice onAuthRequired--->"+errorMessage);
    errorMessage = errorMessage ? errorMessage : null;
    return {
        authRequired: true,
        errorMessage: errorMessage
    };
}
1

1 Answers

0
votes

Your adapter's secret data is protected with realm AuthRealm and whenever client makes request to protected adapter endpoint, it throws 401 unauthorized error. Basically 401 is a challenge thrown by server.

Check whether you have declared registered challenge handler with AuthRealm realm in client code as explained in this tutorial. Once client answers server challenge successfully with the help of challenge handler, server will return the secret data.