VMware Cloud Community
LaxmiRagi
Enthusiast
Enthusiast
Jump to solution

How to build a rest API which can be accept Basic Authorization to get Session

Hi There,

I want to build a rest API that can be accepted Basic authorization to get the session id. I am unable to do so.

function (host, method, requestUrl, content) {

        var restHost = this.getTransientRestHost(host);

       requestUrl = restHost.url + requestUrl;

       System.log("requestUrl "+requestUrl) ;

       var data = (content != "") ? JSON.stringify(content) : null;

       var request = restHost.createRequest(method, requestUrl, data);

       request.contentType = "application/json";

      var user = 'username';

      var pwd = 'password';

      var auth = user+':'+pwd;

      request.setHeader('Authorization' ,'Basic '+auth); //: here I am setting up header like this.

      var response = request.execute();

return response;

};

But, I am getting an error, am I missing something there? please help.

Laxmi

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Yes, you are missing the fact that the value after "Basic " (user + ':' + pwd) must be Base64-encoded.

There are some samples showing how to correctly configure basic authentication with HTTP-REST plug-in; see, for example, https://code.vmware.com/samples?id=2032#code

View solution in original post

0 Kudos
1 Reply
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Yes, you are missing the fact that the value after "Basic " (user + ':' + pwd) must be Base64-encoded.

There are some samples showing how to correctly configure basic authentication with HTTP-REST plug-in; see, for example, https://code.vmware.com/samples?id=2032#code

0 Kudos