Programmatically change credentials in a work light adapter

Am I looking for a way to programmatically set the credentials of an HTTP adapter? Does anyone have an example?

Is it possible to change the adapter js implementation to overwrite credentials?

with something like:

function getMyAdapters(path) {

var tok = "myuser:mypw";
var hash = Base64Encoder.encode(tok);
var headers="{'User-Agent':'Mozilla'"+"Authentication: Basic }"+hash;
var input = {
        method : 'get',
        returnedContentType : 'json',
        headers: headers,
        path : path
    };


return WL.Server.invokeHttp(input);
}

But he failed because he did not find Base64Encoder.

Any idea?

0
source share
1 answer

First, you should use "Authorization" and not "Authentication" as described here: http://en.wikipedia.org/wiki/Basic_access_authentication

In addition, you should do the following:

Create a Java class, something like this (you need to clean and adjust it):

public class Idan {
        public String basicHash(String user, String password) {
            BASE64Encoder base64Encoder = new BASE64Encoder();
            String authorization = user + ":" + password;
            return base64Encoder.encode(authorization.getBytes());
        }

        // to test:
        public static void main(String[] args) {
        Idan i = new Idan();
        System.out.println(i.basicHash("idan", "somepassword"));
    }
}

In the adapter .js file, declare globally:

var idan = new org.Idan();

And the procedure:

function test(){
WL.Logger.debug(idan.basicHash("username_test", "secret_password"));

}

0
source

All Articles