Ibm mobilefirst Worklight 6:针对Web服务使用适配器进行身份验证

Ibm mobilefirst Worklight 6:针对Web服务使用适配器进行身份验证,ibm-mobilefirst,worklight-adapters,Ibm Mobilefirst,Worklight Adapters,我有一个身份验证Web服务,它接受带有www url表单编码编码的POST请求,并以JSON格式响应 我目前正在学习基于适配器的身份验证教程。在SingleStepAuthAdapter impl.js中的submitAuthentication(用户名、密码)主体中,我有以下内容: function submitAuthentication(username,password): var input = { method: "post", path

我有一个身份验证Web服务,它接受带有www url表单编码编码的POST请求,并以JSON格式响应

我目前正在学习基于适配器的身份验证教程。在SingleStepAuthAdapter impl.js中的submitAuthentication(用户名、密码)主体中,我有以下内容:

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)

我遇到的问题是服务器(本地托管的websphere)没有接收到我的用户名和密码。我在这里遗漏了什么吗?

您可以使用基本身份验证凭据向请求添加标头,例如:

var input = {
        method: "post"
        returnedContentType: 'application/json',
        path: path,
        headers: {
                'Authorization': 'Basic '+ base64_encode(username+':'+password),
您还可以发出请求,然后存储一个安全cookie,并将其作为标题附加到后续请求中:


当我添加标题:,我得到org.mozilla.javascript.EcmaError:ReferenceError:“base64_encode”未定义。此外,我使用的Web服务要求在请求正文中包含用户名和密码。您需要编写自己的base64编码方法,或者已经使用了。这可以在服务器端用Javascript甚至本机java编写。这里有更多的信息:如果您正在通过Http进行基本身份验证,我相信需要使用base64编码。如果您想设置一个示例项目并将其上载到drop box或类似的东西,我可以进一步查看它