2013-06-04 124 views
2

我很努力地向受保護的rss提要發送HTTP適配器請求以正確執行。我已經閱讀了大量的IBM文檔,並且追蹤了死鏈接以移動或「維護」IBM頁面。不幸的是,我沒有發現任何示例顯示如何授權此請求。在IBM Worklight中授權HTTP適配器

爲了本示例的緣故,我試圖從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); 
} 

我如何可以通過訪問此飼料所需的憑據?

謝謝!

回答

3

您可以指定身份驗證機制爲適配器XML文件的一部分。文檔在這裏:The Authentication element of the HTTP adapter

我不此刻有工作燈工作室的一個實例,在我的面前來檢查,但我會想象有適配器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> 
+0

太棒了!我以前看過這樣的代碼,但出於某種原因無法使用它,這次它運行得很完美。現在要弄清楚如何通過siteminder進行身份驗證......有趣的部分 – Cmo

+2

@Nick我在哪裏可以找到有關基本身份驗證的文檔? $ {user}和$ {password}變量存儲在哪裏? –

3

Feed如何期待憑證通過?如果使用基本身份驗證,那麼你可以Base64編碼,您的憑據,並通過他們在適配器調用這樣的標題:

function getFeed(){ 

    var input = { 
      method : 'get', 
      headers: {Authorization: "Basic YWRtaW5Ad29ya2xpZ2h0LmlibTpjaGFuZ2VJdCE="}, 
      path : "/hello",    
      returnedContentType : 'plain'  
    }; 

    return WL.Server.invokeHttp(input); 
} 
+0

我確認它的工作! –

相關問題