【问题标题】:Is it possible to use the subscription-key query string parameter with Azure API Management SOAP-passthrough?是否可以将订阅密钥查询字符串参数与 Azure API 管理 SOAP 传递一起使用?
【发布时间】:2018-02-23 12:06:21
【问题描述】:

我们使用 API 管理来公开几个 API。我们公开的 API 之一被配置为 SOAP 直通 API,但我们在 APIM 身份验证方面遇到了一些问题。

当我们使用Ocp-Apim-Subscription-Key 标头传递查询字符串时,一切正常,API 返回的内容正确。

当我们使用subscription-key 查询字符串参数时,API 将返回 401 Unauthorized。我在 Postman 中测试了这种行为,改变发送订阅密钥的方式会导致这种行为。

此 API 的一个实现细节是它公开现有的 WSDL 并通过策略将此 SOAPAction 路由到 Azure 函数。在该函数的 Application Insights 中,我可以验证该函数在我得到 401 时从未被调用,但在我成功调用时被调用(使用标头)。

这是正常行为吗?我做错了吗?还是 APIM 中的错误?

【问题讨论】:

    标签: azure soap azure-api-management api-management


    【解决方案1】:

    这可能是我们为 SOAP Passthrough 进行路由的方式的问题。您会注意到,我们在 API 设置中添加了一个查询参数,以标识操作将匹配到的 SoapAction。将 SoapAction 参数添加到入站请求时,您的 api 键查询参数可能会被覆盖。我会调查并通知您。

    【讨论】:

    • 我们注意到只有在入站策略中执行“设置后端服务”时才会遇到此问题。所以它确实看起来像是路由的问题。我们有一个解决方法,我将作为替代答案发布。
    【解决方案2】:

    我们目前使用以下策略解决此问题。我们发送一个请求并将该请求的响应设置为此 api 的响应,而不是更改策略中的后端服务器 url。您可以在下面找到我们的政策,该政策与查询字符串中的订阅密钥一起使用。

    <policies>
        <inbound>
            <base />
            <send-request mode="copy" response-variable-name="response" timeout="20" ignore-error="false">
                <set-url>{{BackendServer_URL}}</set-url>
            </send-request>
            <!--return-response response-variable-name="reponse" /-->
            <choose>
                <!-- If StatusCode is not OK, return Unauthorized with the reason. -->
                <when condition="@(((IResponse)context.Variables["response"]).StatusCode != 200)">
                    <return-response response-variable-name="reponse">
                        <set-status code="401" reason="Unauthorized" />
                        <set-body>@(((IResponse)context.Variables["response"]).Body.As<string>())</set-body>
                    </return-response>
                </when>
                <otherwise>
                    <return-response response-variable-name="reponse">
                        <set-status code="200" />
                        <set-header name="Content-Type" exists-action="override">
                            <value>text/xml; charset=utf-8</value>
                        </set-header>
                        <set-body>@(((IResponse)context.Variables["response"]).Body.As<string>())</set-body>
                    </return-response>
                </otherwise>
            </choose>
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多