Search code examples
wso2wso2-api-managerckan

How to pass CKAN API authorization token via the WSO2-API Manager


I am using WSO2 API Manager (version 3.0.1) as front-end for accessing data via an API call to CKAN (version 2.8.2).

A private CKAN data set requires an authorization token as described here.

"When calling an API function that requires authorization, you must authenticate yourself by providing your API key with your HTTP request."

CKAN API authorization instructions

How is this accomplished in WSO2? Specifically, what configuration files/settings need to change to make this happen?

I see from this documentation that if configured in Eclipse using a tooling plug-in it can be accomplished with something like this (Step 23):

curl -k -H "Authorization: Bearer api-key-for-WSO2-goes-here" -H "Custom: Bearer api-key-for-CKAN-goes-here" https://my-wso2-host-goes-here:8243/test/1.0.0

WSO2 curl example

However, these instructions require using Eclipse. But how can this be accomplished without Eclipse? I.e. what configuration files/settings need to be modified on the server or in the WSO2 API Publisher and/or the WSO2 API Dev Portal to pass the authorization token for CKAN through WSO2 API-M?


Solution

  • You do not have to use Eclipse for this. In the tutorial Eclispse plugin is used as a tool to generate the sequence easily. In that tutorial we needed a sequence in the first place because the authorization header required by the backend is "Authorization". In WSO2 APIM this is a reserved header to pass the internally generated token. Therefore we first pass the backend token in a custom header with a different header name and then copy this value to Authorization header in the in-sequence. The sequence would look like below.

    <sequence xmlns="http://ws.apache.org/ns/synapse" name="authorization_header_exchange">
    <property name="X-Authorization" expression="get-property('transport', 'X-Authorization')" scope="default" type="STRING"/>
    <property name="Authorization" expression="get-property('X-Authorization')" scope="transport" type="STRING" description=""/>
    <property name="X-Authorization" scope="transport" action="remove"/>
    

    Refer [1] for more info.

    However in your case you can send the api key in X-CKAN-API-Key along with the request itself without using a mediation sequence.

    [1]. https://docs.wso2.com/display/APICloud/Sample+Mediation+Sequences#SampleMediationSequences-Passinganauthorizationheadertoyourbackend