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

时间:2014-04-07 18:10:30

标签: ibm-mobilefirst worklight-adapters

我在http://example.com:9080/auth/login有一个身份验证网络服务,它接受带有www-url-form-encoded编码的 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)没有收到我的用户名和密码。我在这里错过了什么吗?

1 个答案:

答案 0 :(得分:2)

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

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

您也可以发出请求,然后存储一个安全的Cookie,并将其作为标题附加到此帖后的未来请求中:

Attaching cookie to WorkLight Adapter response header

相关问题