【问题标题】:WSO2 API Manager CORSWSO2 API 管理器 CORS
【发布时间】:2016-05-20 05:18:39
【问题描述】:

我想在我的 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>

该文件似乎并未将此 CORS 配置应用于所有端点。在向已发布的 API 端点发出请求时,我收到了正确的访问控制标头,但在点击令牌端点时却没有收到它们(默认 - '/token'、'/revoke')。

我怎样才能做到这一点?

【问题讨论】:

    标签: wso2 cors wso2-am


    【解决方案1】:

    CORS 配置对使用 Publisher 应用程序创建的 API 有效。此配置不涵盖令牌 API(-'/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>
    

    【讨论】:

    • 这就是答案 - 谢谢!我没有足够的声誉来投票给答案,但我会这样做!
    • @BenDavis:如果它回答了你的问题。你应该接受它作为答案
    • 我们走了 - 堆栈溢出 n00b 在这里!谢谢。
    【解决方案2】:

    api-manager.xml 中的 CORS 配置仅适用于通过 API Manager 创建的 API。它不会将这些配置应用于令牌 API,例如 /token 和 /revoke。

    令牌API相关配置位于{PRODUCT_HOME}/repository/deployment/server/synapse-configs/default/api目录。

    如果需要,您可以编辑 _TokenAPI_.xml 并添加 CORS 标头。您可以将[1] 称为有用的资源。

    [1] - http://blog.lakmali.com/2013/10/how-to-add-additional-headers-to-wso2.html

    【讨论】:

    • 感谢您快速准确的回复。我什至不知道这些文件!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多