我希望在我的WSO2 API实例中为所有端点启用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>但是,这个文件似乎并没有将这个CORS配置应用到所有端点。当我向我发布的API端点发出请求时,我会收到正确的访问控制头,但当我点击令牌端点(默认- '/ token ','/revoke')时,我不会接收它们。
我是如何做到这一点的?
发布于 2016-02-10 04:07:52
CORS配置对于使用Publisher应用程序创建的API有效。令牌apis (- '/ token ','/revoke')不在此配置中。
CORS标头使用处理程序进行处理。
org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler如果在/repository/deployment/server/synapse-configs/default/api中打开api的突触配置,就会找到这个处理程序。
您也可以将这个处理程序设置为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>https://stackoverflow.com/questions/35305316
复制相似问题