簡體   English   中英

WSO2 API Manager CORS

[英]WSO2 API Manager CORS

我想在我的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端點發出請求時,我收到了正確的Access Control標頭,但是當我點擊令牌端點時,我沒有收到它們(默認 - '/ token','/ revoke')。

我怎么能做到這一點?

CORS配置對使用Publisher應用程序創建的API有效。 此配置不包括令牌apis( - '/ token','/ revoke')。

使用處理程序處理CORS頭

org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler

如果您在/ 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>

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM