You are developing a solution in Azure API Management (APIM). The API must allow cross-origin requests from a web client hosted at `https://portal.contoso.com`. You configure JSON Web Token (JWT) validation and response caching. During testing, the web client fails to access the API, throwing a CORS error in the browser console. The APIM gateway logs show that preflight `OPTIONS` requests are failing with an HTTP `401 Unauthorized` status code. You review the following policy configuration:
xml
<policies>
<inbound>
<base />
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized">
<openid-config url="https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration" />
<required-claims>
<claim name="aud">
<value>api://portal-backend</value>
</claim>
</required-claims>
</validate-jwt>
<cors allow-credentials="true">
<allowed-origins>
<origin>https://portal.contoso.com</origin>
</allowed-origins>
<allowed-methods>
<value>GET</value>
<value>POST</value>
</allowed-methods>
</cors>
<cache-lookup vary-by-developer="false" vary-by-developer-groups="false" downstream-caching-type="none">
<vary-by-query-parameter>id</vary-by-query-parameter>
</cache-lookup>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<cache-store duration="60" />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Which change should you apply to the policy configuration to resolve the CORS error?
- AMove the CORS policy from the inbound section to the outbound section.
- BConfigure the APIM instance to use a user-assigned managed identity to authorize the CORS origin dynamically through a Key Vault reference.
- Move the CORS policy so that it is defined before the JWT validation policy within the inbound element.Answer
- DStore the client credentials in Azure Key Vault and configure a Key Vault access policy to allow the APIM gateway to bypass JWT validation for the OPTIONS HTTP method.