微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CORS 策略不适用于带有应用服务的 Azure APIM

如何解决CORS 策略不适用于带有应用服务的 Azure APIM

我正在使用适用于我的应用服务的 Azure APIM 策略管理 CORS 规则。以下策略适用于“所有操作”级别。在 API 级别,它只是使用内部入站从上述范围继承这一点。

我的问题是该政策根本没有得到应用。我也可以从邮递员和浏览器拨打电话。我只想允许少数域访问我的 API。

根据我的理解,如果您设置如下所示的策略并在出站中设置了适当的标头。预取由 APIM 处理,用户应该无法从邮递员或浏览器访问。只有在允许列表中的域才能访问。这是一个公共功能,所以我只关心设置正确的 cors 规则。如果我遗漏了什么,请告诉我。

<policies>
    <inbound>
        <cors>
            <allowed-origins>
                <origin>http://localhost:3000</origin>
            </allowed-origins>
            <allowed-methods preflight-result-max-age="300">
                <method>GET</method>
            </allowed-methods>
            <allowed-headers>
                <header>accept</header>
                <header>Content-Type</header>
            </allowed-headers>
        </cors>
        <set-backend-service base-url="https://test" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <set-header name="Access-Control-Allow-Origin" exists-action="override">
            <value>@(context.Request.Headers.GetValueOrDefault("Origin",""))</value>
        </set-header>
        <set-header name="Access-Control-Allow-Credentials" exists-action="override">
            <value>true</value>
        </set-header>
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。