Azure:按照官方文档设置APIM入站策略时抛出错误

5lwkijsr  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(105)

我严格按照这个文档上的步骤进行操作,但在保存策略编辑器“入站处理”和代码视图按钮“</>”时出现了这个错误:

One or more fields contain incorrect values:
Error in element 'cors' on line 2, column 5: Policy section is not allowed in the specified scope
Error in element 'validate-jwt' on line 16, column 5: Policy section is not allowed in the specified scope
Error in element 'rate-limit-by-key' on line 24, column 5: Policy section is not allowed in the specified scope

代码如下:

<inbound>
   <cors allow-credentials="true">
         <allowed-origins>
             <origin>https://devjohn1.z11.web.core.windows.net/</origin>
         </allowed-origins>
         <allowed-methods preflight-result-max-age="120">
             <method>GET</method>
         </allowed-methods>
         <allowed-headers>
             <header>*</header>
         </allowed-headers>
         <expose-headers>
             <header>*</header>
         </expose-headers>
   </cors>
   <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid." require-expiration-time="true" require-signed-tokens="true" clock-skew="300">
      <openid-config url="https://devjohn1.b2clogin.com/devjohn1.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1_myapp_frontend_devjohn1_signupandsignin" />
      <required-claims>
         <claim name="aud">
            <value>56f39849-19eb-49d6-qweqw-123123123</value>
         </claim>
      </required-claims>
   </validate-jwt>
   <rate-limit-by-key calls="300" renewal-period="120" counter-key="@(context.Request.IpAddress)" />
   <rate-limit-by-key calls="15" renewal-period="60" counter-key="@(context.Request.Headers.GetValueOrDefault("Authorization","").AsJwt()?.Subject)" />
</inbound>

有什么不对的?我只是按照步骤...

rqcrx0a6

rqcrx0a61#

    • 我试图在我的环境中重现该问题,但得到了如下相同的错误**-

一个或多个字段包含不正确的值:

  • 第2行第10列的元素“cors”中有错误:在指定的范围内不允许使用策略节
  • 第10列第16行的元素“validate-jwt”中出错:在指定的范围内不允许使用策略节
  • 第24行第10列的“rate-limit-by-key”元素中出错:在指定的范围内不允许使用策略节

每当您尝试以以下方式保存策略时,您将收到错误信息

在APIM中创建新API后,单击入站策略代码编辑器

单击后,您将获得默认策略模板。将入站策略粘贴到<inbound></inbound>中,保持其他标签不变。

在你的现有政策的几个修改后,我能够保存它。将<inbound></inbound>保持在<policies></policies>范围内。

<policies>
    <inbound>
        <cors allow-credentials="true">
            <allowed-origins>
                <origin>https://devjohn1.z11.web.core.windows.net/</origin>
            </allowed-origins>
            <allowed-methods preflight-result-max-age="120">
                <method>GET</method>
            </allowed-methods>
            <allowed-headers>
                <header>*</header>
            </allowed-headers>
            <expose-headers>
                <header>*</header>
            </expose-headers>
        </cors>
        <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid." require-expiration-time="true" require-signed-tokens="true" clock-skew="300">
            <openid-config url="https://devjohn1.b2clogin.com/devjohn1.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1_myapp_frontend_devjohn1_signupandsignin" />
            <required-claims>
                <claim name="aud">
                    <value>56f39849-19eb-49d6-qweqw-123123123</value>
                </claim>
            </required-claims>
        </validate-jwt>
        <rate-limit-by-key calls="300" renewal-period="120" counter-key="@(context.Request.IpAddress)" />
        <rate-limit-by-key calls="15" renewal-period="60" counter-key="@(context.Request.Headers.GetValueOrDefault("Authorization","").AsJwt()?.Subject)" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

相关问题