是否可以将 subscription-key 查询字符串参数与 Azure API 管理 SOAP-passthrough 一起使用?
Is it possible to use the subscription-key query string parameter with Azure API Management SOAP-passthrough?
我们用API管理暴露几个API的。我们公开的 API 之一被配置为 SOAP-passthrough API 但我们在 APIM.
的身份验证方面面临一些问题
当我们使用 Ocp-Apim-Subscription-Key
header 传递查询字符串时,它一切正常并且 API 返回它的内容是正确的。
当我们使用 subscription-key
查询字符串参数时,API 返回 401 Unauthorized。我在 Postman 中测试了这种行为,更改发送订阅密钥的方式导致了这种行为。
这个 API 的一个实现细节是它公开一个现有的 WSDL 并通过策略将这个 SOAPAction 路由到 Azure Functions。在该函数的 Application Insights 中,我可以验证该函数在我收到 401 时从未被调用,但在我成功调用时被调用(使用 header)。
这是正常现象吗?我做错了吗?还是 APIM 中的错误?
这可能与我们为 SOAP 传递进行路由的方式有关。您会注意到在 API 设置中,我们添加了一个查询参数来标识操作将匹配到的 SoapAction。将 SoapAction 参数添加到入站请求时,您的 api 关键查询参数可能会被覆盖。我会调查并告知您。
我们目前使用以下策略解决此问题。我们没有更改策略中的后端服务器 url,而是发送请求并将该请求的响应设置为对此 api 的响应。您可以在下面找到我们的政策,该政策与查询字符串中的订阅密钥一起使用。
<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>
我们用API管理暴露几个API的。我们公开的 API 之一被配置为 SOAP-passthrough API 但我们在 APIM.
的身份验证方面面临一些问题当我们使用 Ocp-Apim-Subscription-Key
header 传递查询字符串时,它一切正常并且 API 返回它的内容是正确的。
当我们使用 subscription-key
查询字符串参数时,API 返回 401 Unauthorized。我在 Postman 中测试了这种行为,更改发送订阅密钥的方式导致了这种行为。
这个 API 的一个实现细节是它公开一个现有的 WSDL 并通过策略将这个 SOAPAction 路由到 Azure Functions。在该函数的 Application Insights 中,我可以验证该函数在我收到 401 时从未被调用,但在我成功调用时被调用(使用 header)。
这是正常现象吗?我做错了吗?还是 APIM 中的错误?
这可能与我们为 SOAP 传递进行路由的方式有关。您会注意到在 API 设置中,我们添加了一个查询参数来标识操作将匹配到的 SoapAction。将 SoapAction 参数添加到入站请求时,您的 api 关键查询参数可能会被覆盖。我会调查并告知您。
我们目前使用以下策略解决此问题。我们没有更改策略中的后端服务器 url,而是发送请求并将该请求的响应设置为对此 api 的响应。您可以在下面找到我们的政策,该政策与查询字符串中的订阅密钥一起使用。
<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>