【问题标题】:Authorizing HTTP Adapter in IBM Worklight在 IBM Worklight 中授权 HTTP 适配器
【发布时间】:2013-05-31 02:14:56
【问题描述】:

我正在努力让受保护的 rss 提要的 HTTP 适配器请求正确执行。我已经阅读了大量 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);
}

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

谢谢!

【问题讨论】:

    标签: ibm-mobilefirst


    【解决方案1】:

    您可以将身份验证机制指定为适配器 XML 文件的一部分。文档在这里:The Authentication element of the HTTP adapter

    目前我面前没有要检查的 Worklight Studio 实例,但我想有一个适配器 XML 的设计视图或一些自动完成功能来帮助填写详细信息的指定方式在&lt;authentication&gt; 块中。

    示例:

    <?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>
    

    【讨论】:

    • 太棒了!我以前见过这样的代码,但由于某种原因在使用它时遇到了麻烦,这次它完美无缺。现在弄清楚如何通过站点管理员进行身份验证...有趣的部分
    • @Nick 我在哪里可以找到有关此类基本身份验证的文档? ${user} 和 ${password} 变量存储在哪里?
    【解决方案2】:

    提要如何传递凭据?如果它使用的是基本身份验证,那么您可以对您的凭据进行 base64 编码并将它们传递到适配器调用的标头中,如下所示:

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

    【讨论】:

      猜你喜欢
      • 2016-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      • 2015-10-25
      • 2014-01-17
      相关资源
      最近更新 更多