在IBM Worklight中授权HTTP适配器



我正在努力获得一个HTTP适配器请求到一个受保护的rss提要正确执行。我已经阅读了大量的IBM文档,也在寻找已移动或"正在维护"的IBM页面的死链接。不幸的是,我找到的示例中没有一个显示如何授权此请求。

在本例中,我试图从IBM Greenhouse Environment中的Connections安装访问rss提要。

适配器XML:

<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="exampleAdapter"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:wl="http://www.worklight.com/integration"
    xmlns:http="http://www.worklight.com/integration/http">
    <displayName>feedRead</displayName>
    <description>feedRead</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>https</protocol>
            <domain>greenhouse.lotus.com</domain>
            <port>443</port>
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="2" />
    </connectivity>
   <procedure name="getFeed" connectAs="server"/>
</wl:adapter>

适配器. js:

function getFeed() {
    var input = {
        method : 'get',
        returnedContentType : 'xml',
        path : 'connections/opensocial/basic/rest/activitystreams/@me/@all/@all?    rollup=true&format=atom'
    };
    return WL.Server.invokeHttp(input);
}

如何传递访问此提要所需的凭据?

谢谢!

您可以将身份验证机制指定为适配器XML文件的一部分。HTTP适配器的Authentication元素。

我现在没有Worklight Studio的实例来检查,但我可以想象有一个适配器XML的设计视图或一些自动完成功能来帮助填充应该如何在<authentication>块中指定的细节。

例子:

<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="exampleAdapter"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:wl="http://www.worklight.com/integration"
    xmlns:http="http://www.worklight.com/integration/http">
    <displayName>feedRead</displayName>
    <description>feedRead</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>https</protocol>
            <domain>greenhouse.lotus.com</domain>
            <port>443</port>
            <authentication>
                <basic/>
                <serverIdentity>
                    <username> ${user} </username>
                    <password> ${password} </password>
                </serverIdentity>
            </authentication>  
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="2" />
    </connectivity>
   <procedure name="getFeed" connectAs="server"/>
</wl:adapter>

提要如何期望凭据被传递?如果使用Basic Auth,那么您可以对凭证进行base64编码,并在适配器调用的头中传递它们,如下所示:

function getFeed(){
    var input = {
            method  : 'get',
            headers: {Authorization: "Basic YWRtaW5Ad29ya2xpZ2h0LmlibTpjaGFuZ2VJdCE="},
            path : "/hello",            
            returnedContentType : 'plain'       
    };
    return WL.Server.invokeHttp(input);
}

最新更新