Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
version 2.18.0
i am try to login in open-search dashboard using asp .net core mvc (my project)
there are make JavaScript to get cookie and set into my project(mvc)
there are error cors like below
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:5601/auth/login. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 404.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:5601/auth/login. (Reason: CORS request did not succeed). Status code: (null).
how to set cors in opensearch dashboard and get cookie and set in iframe
<iframe src="http://127.0.0.1:5601/app/dashboards?security_tenant=global#/view
/19250d30-d3d8-11ef-8d1a-4140f1909bb9?embed=true&_g=(filters:!(),refreshInterval
:(pause:!t,value:0),time:(from:now-90d,to:now))&_a=(description:'',filters:!(),
fullScreenMode:!f,options:(hidePanelTitles:!f,useMargins:!t),query:
(language:kuery,query:''),timeRestore:!f,title:test_dash,viewMode:view)"
height="600" width="800"></iframe>
<script>
$.ajax({
url: "http://127.0.0.1:5601/auth/login",
method: "POST",
crossDomain: true,
contentType: "application/json",
data: JSON.stringify({
username: "admin",
password: "admin"
}),
xhrFields: {
withCredentials: true
},
headers: {
"osd-version": "2.18.0",
"osd-xsrf": "osd-fetch",
"Accept": "application/json",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "cross-site",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Credentials": true
},
success: function(response) {
console.log("Login successful:", response);
console.log("Cookies:", document.cookie); // Access cookies
},
error: function(xhr, status, error) {
console.error("Error:", status, error);
}
});
</script>