Hello,
I want to generate authorized access token for D365 CRM online to perform an operation using java script.
I have tried some code for the same but it throws an error of Cross Origin in browser, also apply the headers by lots of searching related to it and for the cross origin i have passed all the header something like "Access-Control-Allow-Origin", "*" in the request.
But it didn't work.
I got error as shown below,
Here is the code which i have written,
var data = new FormData();
data.append("client_id", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX");
data.append("grant_type", "client_credentials");
data.append("resource", "abc@.crm8.dynamics.com");
data.append("client_secret", "XXXXXXXXXXXXXXXXXXX");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("POST", "">login.microsoftonline.com/.../token",false);
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("Access-Control-Allow-Credentials", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Access-Control-Allow-Methods" , "GET, POST, DELETE, PUT");
xhr.setRequestHeader("Access-Control-Allow-Headers", "x-requested-with credentials");
xhr.send(data);
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
Please Help.