首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WSO2 API管理器CORS

WSO2 API管理器CORS
EN

Stack Overflow用户
提问于 2016-02-10 01:25:09
回答 1查看 6.1K关注 0票数 7

我希望在我的WSO2 API实例中为所有端点启用CORS。我已经看过文档(这很棒),它建议修改repository/conf/api-manager.xml文件,因为其中有一个CORS配置节点(如下所示)。

代码语言:javascript
复制
<!--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')时,我不会接收它们。

我是如何做到这一点的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-10 04:07:52

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

CORS标头使用处理程序进行处理。

代码语言:javascript
复制
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).在配置文件中应该是这样的。

代码语言:javascript
复制
 <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>
票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35305316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档