[英]Include CORS Headers in WSO2 APIM 4.0.0 Token API Response
[英]WSO2 Api Manger 3.0.0 Token API CORS issue with Angular Application
我一直在使用 WSO2 API Manager 3.0.0 单节点设置。 我面临着调用用于获取令牌的令牌 API(可从https://host:port/token?grant_type=client_credentials 获得)的挑战。 在检查了几个博客后,我发现有几个文件需要更改。 论文是——
Files: _TokenAPI_.xml and _RevokeAPI_.xml
Files Location: /usr/lib64/wso2/wso2am/3.0.0/repository/deployment/server/synapse-configs/default/api
我已按照以下代码进行了更改 -
<handlers>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
<property name="apiImplementationType" value="ENDPOINT"/>
<property name="allowHeaders" value="authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction"/>
<property name="allowedOrigins" value="*"/>
<property name="AuthorizationHeader" value="Authorization"/>
<property name="allowedMethods" value="GET,PUT,POST,DELETE,PATCH,OPTIONS"/>
<property name="allowCredentials" value="true"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerCacheExtensionHandler"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.common.SynapsePropertiesHandler"/>
</handlers>
我正在使用 Angular 应用程序调用令牌 API,但调用仍然不成功并导致 CORS 问题。 我还尝试从文件名中删除下划线( _ )并将它们重命名为 TokenAPI.xml 和 RevokeAPI.xml 但仍然没有运气。 你能帮忙吗?下面是完整的 XML
_TokenAPI_.xml
<api xmlns="http://ws.apache.org/ns/synapse" name="_WSO2AMTokenAPI_" context="/token"> <resource methods="POST" url-mapping="/*" faultSequence="_token_fault_"> <inSequence> <property name="uri.var.portnum" expression="get-property('keyManager.port')"/> <property name="uri.var.hostname" expression="get-property('keyManager.hostname')"/> <send> <endpoint> <http uri-template="https://{uri.var.hostname}:{uri.var.portnum}/oauth2/token"> <timeout> <duration>60000</duration> <responseAction>fault</responseAction> </timeout> </http> </endpoint> </send> </inSequence> <outSequence> <send/> </outSequence> </resource> <handlers> <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler"> <property name="apiImplementationType" value="ENDPOINT"/> <property name="allowHeaders" value="authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction"/> <property name="allowedOrigins" value="*"/> <property name="AuthorizationHeader" value="Authorization"/> <property name="allowedMethods" value="GET,PUT,POST,DELETE,PATCH,OPTIONS"/> <property name="allowCredentials" value="true"/> </handler> <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerCacheExtensionHandler"/> <handler class="org.wso2.carbon.apimgt.gateway.handlers.common.SynapsePropertiesHandler"/> </handlers> </api>
[编辑] 我的 API 管理器和 Angular 应用程序运行在不同的环境中,即不同的虚拟机。
您可以使用 API 网关 CORS 处理程序
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
在令牌 API 中也是如此。 添加后,您的_TokenAPI_.xml
文件应如下所示
<api xmlns="http://ws.apache.org/ns/synapse" name="_WSO2AMTokenAPI_" context="/token">
<resource methods="POST" url-mapping="/*" faultSequence="_token_fault_">
<inSequence>
<property name="uri.var.portnum" expression="get-property('keyManager.port')"/>
<property name="uri.var.hostname" expression="get-property('keyManager.hostname')"/>
<send>
<endpoint>
<http uri-template="https://{uri.var.hostname}:{uri.var.portnum}/oauth2/token">
<timeout>
<duration>60000</duration>
<responseAction>fault</responseAction>
</timeout>
</http>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
<handlers>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerCacheExtensionHandler"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
<property name="apiImplementationType" value="ENDPOINT"/>
<property name="AuthorizationHeader" value="Authorization"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.common.SynapsePropertiesHandler"/>
</handlers>
</api>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.