Authorizing HTTP Adapter in IBM Worklight

2019-01-26 00:10发布

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!

2条回答
贪生不怕死
2楼-- · 2019-01-26 00:48

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);
}
查看更多
疯言疯语
3楼-- · 2019-01-26 01:02

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>
查看更多
登录 后发表回答