我想在其中一个 api 中应用此策略,以将其收到的令牌重定向到 api https://obw.stdn.com.pe/api/mf/v3/ami/authorize
<policies>
<inbound>
<validate-jwt header-name="Authorization"
failed-validation-httpcode="401"
failed-validation-error-message="Unauthorized. Access token is missing or invalid.">
<openid-config url="https://uatidpbsp.b2clogin.com/uatidpbsp.onmicrosoft.com/B2C_1A_LOGIN_OOBB/v2.0/.well-known/openid-configuration" />
<audiences>
<audience>01c396bf-e852-b396-d0a7e4d0d373</audience>
<audience>c2ef0c9f-98f1-920e-44fb99c98026</audience>
</audiences>
<issuers>
<issuer>https://uatidpbsp.b2clogin.com/a359g4c43-4228-563k5-89b6/v2.0/</issuer>
</issuers>
</validate-jwt>
<!-- Send the request to the external endpoint with the token -->
<send-request mode="new">
<set-url>https://obw.stdn.com.pe/api/mf/v3/ami/authorize</set-url>
<set-method>POST</set-method>
<set-header name="Authorization" exists-action="override">
<value>Bearer @(context.Request.Headers.GetValueOrDefault("Authorization", ""))</value>
</set-header>
<set-header name="Ocp-Apim-Subscription-Key" exists-action="override">
<value>e75ee8762a842htf96e36ba5f9z8c275</value>
</set-header>
<set-body>
<value>{}</value>
</set-body>
</send-request>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
我收到以下错误:
Some of the policy expressions may not have the correct parentheses or braces format. Please ensure that all policy expressions are in the correct format @() or @{}, in order to avoid any issues.
当我尝试保存策略时,出现语法错误。
发送请求策略需要进行两项修改:
需要响应变量
<send-request mode="new" response-variable-name="responseExternal">
主体值的大括号必须被删除
<set-body><value /></set-body>
完整政策:
<policies>
<inbound>
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid.">
<openid-config url="https://uatidpbsp.b2clogin.com/uatidpbsp.onmicrosoft.com/B2C_1A_LOGIN_OOBB/v2.0/.well-known/openid-configuration" />
<audiences>
<audience>01c396bf-e852-b396-d0a7e4d0d373</audience>
<audience>c2ef0c9f-98f1-920e-44fb99c98026</audience>
</audiences>
<issuers>
<issuer>https://uatidpbsp.b2clogin.com/a359g4c43-4228-563k5-89b6/v2.0/</issuer>
</issuers>
</validate-jwt>
<!-- Send the request to the external endpoint with the token -->
<send-request mode="new" response-variable-name="responseExternal">
<set-url>https://obw.stdn.com.pe/api/mf/v3/ami/authorize</set-url>
<set-method>POST</set-method>
<set-header name="Authorization" exists-action="override">
<value>Bearer @(context.Request.Headers.GetValueOrDefault("Authorization", ""))</value>
</set-header>
<set-header name="Ocp-Apim-Subscription-Key" exists-action="override">
<value>e75ee8762a842htf96e36ba5f9z8c275</value>
</set-header>
<set-body>
<value />
</set-body>
</send-request>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>