WSO2 API Manager CORS

Ben*_*ies 5 wso2 cors wso2-api-manager

我想在我的WSO2 API Manager实例上为所有端点启用CORS.我已经阅读了文档(这很棒)并建议更改repository/conf/api-manager.xml文件,因为其中有一个CORS配置节点(如下).

<!--Configuration to enable/disable sending CORS headers in the Gateway response
    and define the Access-Control-Allow-Origin header value.-->
<CORSConfiguration>

    <!--Configuration to enable/disable sending CORS headers from the Gateway-->
    <Enabled>true</Enabled>

    <!--The value of the Access-Control-Allow-Origin header. Default values are
        API Store addresses, which is needed for swagger to function.-->
    <Access-Control-Allow-Origin>*</Access-Control-Allow-Origin>

    <!--Configure Access-Control-Allow-Methods-->
    <Access-Control-Allow-Methods>GET,PUT,POST,DELETE,PATCH,OPTIONS</Access-Control-Allow-Methods>

    <!--Configure Access-Control-Allow-Headers-->
    <Access-Control-Allow-Headers>authorization,Access-Control-Allow-Origin,Content-Type</Access-Control-Allow-Headers>

<!--Configure Access-Control-Allow-Credentials-->
<!-- Specifying this header to true means that the server allows cookies (or other user credentials) to be included on cross-origin requests.
     It is false by default and if you set it to true then make sure that the Access-Control-Allow-Origin header does not contain the wildcard (*)
-->
<Access-Control-Allow-Credentials>true</Access-Control-Allow-Credentials>

</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)

但是,此文件似乎不会将此CORS配置应用于所有端点.在向我发布的API端点发出请求时,我收到了正确的Access Control标头,但是当我点击令牌端点时,我没有收到它们(默认 - '/ token','/ revoke').

我怎么能做到这一点?

Cha*_*ake 13

CORS配置对使用Publisher应用程序创建的API有效.此配置不包括令牌apis( - '/ token','/ revoke').

使用处理程序处理CORS头

org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler
Run Code Online (Sandbox Code Playgroud)

如果您在/ repository/deployment/server/synapse-configs/default/api中打开api的synapse配置,您会找到此处理程序.

您也可以将此处理程序设置为RevokeAPI .xml和TokenAPI .xml.(它们位于相同的位置/ repository/deployment/server/synapse-configs/default/api).它在配置文件中会是这样的

 <handlers>
    <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
     <property name="apiImplementationType" value="ENDPOINT"/>
    </handler>
    <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerCacheExtensionHandler"/>
    <handler class="org.wso2.carbon.apimgt.gateway.handlers.common.SynapsePropertiesHandler"/>
</handlers>
Run Code Online (Sandbox Code Playgroud)

  • 我们去吧 - Stack Overflow n00b!谢谢. (2认同)