gpt4 book ai didi

wso2 - CORS 在 wso2 身份服务器中被阻止

转载 作者:行者123 更新时间:2023-12-04 01:39:10 26 4
gpt4 key购买 nike

我将 WSO2is 5.7.0 与我的 angular 6 应用程序一起使用,我尝试从我的应用程序进行 api 调用,但出现 cors 错误:Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
我已经激活了在 oauth 和 authenticationendpoint 中启用的 cors,我用以下几行编辑了两个 webapps 的 de WEB-INF/web.xml:

<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>


在 authenticationendpoint 中,我将 cors 库从 oauth 复制到 lib 文件夹中的 authenticationendpoint webapps 并使用以下行编辑 pom.xml 文件:

<dependency>
<groupId>com.thetransactioncompany.wso2</groupId>
<artifactId>cors-filter</artifactId>
<version>1.7.0.wso2v1</version>
</dependency>


之后,重启服务,我和 Cross-Origin Request Blocked有同样的问题

在我的 angular 应用服务中,我提出如下请求:
const httpHeaders = {
headers: new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded')
.set('Access-Control-Allow-Origin', '*')
};

this.http.post<any>(`http://localhost:9443/commonauth`, payload, httpHeaders)

我认为必须从 tomcat 启用 cors 支持,但我不知道怎么做,除了启用 cors 之外我还有什么其他选择?

我的消息来源:
https://docs.wso2.com/display/IS570/Invoking+an+Endpoint+from+a+Different+Domain https://hasanthipurnima.blogspot.com/2016/05/applying-cors-filter-to-wso2-identity.html

最佳答案

您尝试调用的端点在 Identity Server 中注册为 servlet,您需要在 repository/conf/tomcat/carbon/WEB-INF/ 中配置 web.xml 文件以将 header 应用到端点。

您可以将 org.apache.catalina.filters.CorsFilter 添加到上述文件中以允许所需的域。更多信息可以从 tomcat documentation 找到。示例配置如下所示。

<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>https://www.somedomain.com</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/commonauth</url-pattern>
</filter-mapping>

关于wso2 - CORS 在 wso2 身份服务器中被阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58301123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com