【发布时间】:2017-04-06 13:24:43
【问题描述】:
curl -v -X POST -H "Authorization: Basic <base64 encoded client id:client secret value>" -k -d "grant_type=password&username=<username>&password=<password>" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token
(来自https://docs.wso2.com/display/IS520/Resource+Owner+Password+Credentials+Grant )
这个'curl'命令完美运行。但是当尝试通过ajax调用它时:
$.ajax({
type: 'POST',
data: 'grant_type=password&username=admin&password=admin',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic Z0hLUlA3eThYTmJydl9JR1pJemxDQ1VJQlo0YTozT2VLaUlmUVViMk1yZzZ2YU5uQVFsWFpDU29h'
},
url: 'https://localhost:9443/oauth2/token',
success: function(data) {
console.log(data);
}
})
};
我收到此错误:“XMLHttpRequest 无法加载 https://localhost:9443/oauth2/token。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。来源'null' 因此不允许访问。”
如何配置 WSO2 IS 来处理它?或者有替代方案吗?
WSO2 API Manager (WSO2 API Manager CORS) 也存在类似问题。但是 WSO2 IS 中没有这样的目录 '/repository/deployment/server/synapse-configs/'。
【问题讨论】:
标签: ajax rest wso2 cors wso2is