[英]How to make Azure API Management (API Gateway) CORS policy dynamic?
我想在Azure API網關中動態地在allowed-origins部分添加域(起源)。 可能嗎 ? 或者我們可以設置CORS的另一種方式,以便我們可以動態地允許原點。
<cors>
<allowed-origins>
<origin>http://www.example.com</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
</cors>
您無法動態添加元素到策略配置,但您可以為它們動態提供值( https://docs.microsoft.com/en-us/azure/api-management/api-management-policy-expressions ):
<cors>
<allowed-origins>
<origin>@(context.Request.Url.ToUri().GetLeftPart(UriPartial.Authority))</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
</cors>
我發現了一種我提到的方式。
<inbound>
<base />
<send-request mode="new" response-variable-name="variable" timeout="600" ignore-error="true">
<set-url>@("http://MyDomain/ApiMethod?Origin="(string)context.Request.Headers["Origin"].Last())</set-url>
<set-method>GET</set-method>
<set-body />
</send-request>
<cors>
<allowed-origins>
<origin>@((string)((IResponse)context.Variables["variable"]).Body.As<JObject>(true)["Origin"])</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
</cors>
</inbound
<origin></origin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.