Authorizing HTTP Adapter in IBM Worklight

只谈情不闲聊 提交于 2019-12-18 05:17:12

问题


I am struggling to get an HTTP Adapter request to a protected rss feed to execute properly. I have read a ton of IBM's documentation, as well as chasing dead links to moved or "under maintenance" IBM pages. Unfortunately, none of the examples I have found show how to authorize this request.

For the sake of this example, I am trying to access an rss feed from the Connections installation in the IBM Greenhouse Environment.

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

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);
}

How can I pass the credentials required to access this feed?

Thanks!


回答1:


You can specify the authentication mechanism as part of the adapter XML file. Documentation is here: The Authentication element of the HTTP adapter.

I don't have an instance of Worklight Studio in front of me at the moment to check but I would imagine that there is a design view of the adapter XML or some auto completion features to help fill how the details should be specified in the <authentication> block.

Example:

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



回答2:


How is the feed expecting the credentials to be passed? If it is using Basic Auth, then you can base64 encode your credentials and pass them in the header of the adapter call like this:

function getFeed(){

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

    return WL.Server.invokeHttp(input);
}


来源:https://stackoverflow.com/questions/16921978/authorizing-http-adapter-in-ibm-worklight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!