external/Third 方 API 在 WSO2 APIM 中如何处理外部身份验证

How the external authentication handled in WSO2 APIM for an external/Third Party APIs

我正在使用 WSO2 APIM (2.5.0) 和 IS (5.6.0)。它们都集成在一起并且运行良好。

现在,如果我在 API 管理中加入第三方 API 并使用 oauth 令牌,我就可以访问它。但问题是如何处理任何具有自己身份验证的外部或第三方 API。

SO 基本上,使用 WSO2 APIM 令牌我可以访问入职 API 来使用,但我们将无法获得任何回应,因为入职 API有自己的身份验证(基本或 oauth)。

如何在 APIM.

中实现

任何帮助或指导都会有所帮助。

编辑: 这是我正在使用的序列(感谢 Bee 的指导)

<sequence xmlns="http://ws.apache.org/ns/synapse" name="backend-token-sequence">
<property name="inputmessage" expression="get-property('registry', 'gov:/Login/msg/inputmessage.json')" scope="default" type="STRING"/>

               <script language="js">
               var payload = mc.getProperty("inputmessage");  
               mc.setPayloadJSON(payload)
               </script>
               <header name="Content-Type" scope="transport" value="application/json"/>
               <property name="messageType" value="application/json" scope="axis2" type="STRING" description="messageType"/>
               <property name="temp" expression="$axis2:REST_URL_POSTFIX"/>
               <property name="REST_URL_POSTFIX" action="remove" scope="axis2"/>
               <property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>

<call blocking="true">
    <endpoint>
         <http uri-template="https://xx.com/auth/login" method="POST" />
    </endpoint>
</call>
<property name="x-access-token" scope="transport" expression="json-eval($.token)"/>
<property name="REST_URL_POSTFIX" scope="axis2" expression="$ctx:temp"/>

</sequence>

这是用于 API 之一的流入序列。 我正在调用 API 使用 APIM URL 和 GET 方法,传递 APIM 不记名令牌

谢谢

WSO2 APIM 开箱即用支持 basic auth and digest auth 作为后端安全模式。

除此之外,使用 custom sequences 您可以将任何类型的安全令牌传递到后端。

对于使用 OAuth 的后端,您有 2 个选项。

(1) 在 API 请求中也发送后端令牌(入站到 APIM),然后将其转发到后端。

(2) 使用自定义序列调用外部token API 并为后端取一个新的token 然后转发给后端

<property name="temp" expression="$axis2:REST_URL_POSTFIX"/>
<property name="REST_URL_POSTFIX" action="remove" scope="axis2"/>
<call blocking="true">
    <endpoint>
         <http uri-template="https://external_idp.com/token" method="GET" />
    </endpoint>
</call>
<property name="BackendAuthHeader" scope="transport" expression="json-eval($.tokenresponse.token)"/>
<property name="REST_URL_POSTFIX" scope="axis2" expression="$ctx:temp"/>

我推荐 (1),因为它很简单。

编辑: 有关选项的更多信息 (1)

如果您的后端需要 header 不同于 "Authorization" header 的东西,您只需将 header 与您的请求一起发送,它就会被发送到后端。

但是,如果您的后端也需要 "Authorization" header,那么它就会发生冲突,因为您不能使用相同的 header 来传递 2 个令牌(1 个用于 GW和 1 用于后端)。要解决该问题,您可以使用 custom authorization header for gateway 功能。