我将 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,我编辑了deWEB-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
在我的角度应用程序服务中,我提出如下请求:
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