0

I have an authentication webservice sitting at http://example.com:9080/auth/login that accepts a POST request with www-url-form-encoded encoding and responds back in JSON format.

I am currently going through the Adapter-based Authentication tutorial. Inside the body of submitAuthentication(username, password) in SingleStepAuthAdapter-impl.js, I have the following:

function submitAuthentication(username,password):
     var input = {
         method: "post",
         path: '/auth/login',
         returnedContentType: 'json',
         body: {
            content: JSON.stringify({"username":username, "password":password}),
            contentType: "application/x-www-url-formencoded;charset=utf-8"
         }
var returnData = WL.Server.invokeHttp(input)

The problem I am having is that the server (locally hosted websphere) is not receiving my username and password. Am I missing something here?

Stealth
  • 1,559
  • 4
  • 16
  • 34

1 Answers1

2

You could add a header to the request with basic authentication credentials such as:

var input = {
        method: "post"
        returnedContentType: 'application/json',
        path: path,
        headers: {
                'Authorization': 'Basic '+ base64_encode(username+':'+password),

You could also make the request and then store a secure cookie and attach it as a header on future requests following this post:

Attaching cookie to WorkLight Adapter response header

Community
  • 1
  • 1
Joshua Alger
  • 2,122
  • 1
  • 14
  • 25
  • When I added the headers:, I get org.mozilla.javascript.EcmaError: ReferenceError: "base64_encode" is not defined. – Stealth Apr 07 '14 at 20:42
  • Also, the webservice I am using expects the username and password in the body of request. – Stealth Apr 07 '14 at 20:58
  • You will need to write your own base64 encoding method or utilize one already. This can be written in Javascript or even native java on the server side. Here is some more info: http://stackoverflow.com/questions/246801/how-can-you-encode-a-string-to-base64-in-javascript if you are doing basic authentication over Http I believe base64 encoding is needed. If you want to setup a sample project and upload it to drop box or something similar I can take a further look at it – Joshua Alger Apr 08 '14 at 00:54