Hi All,
I am new to dynamics, need help!!
I am getting entity data from another separate dynamics instance using web api using JavaScript. Getting the the token first (login.microsoftonline.com/{{Tenant ID}}/oauth2/token) using client ID and client secrete (by created azure app and created application user in host dynamics instance ) and using this Bearer token getting the data from target CRM instance using web api inside a customer service portal.
Issue: When I am trying to hit the url ((login.microsoftonline.com/{{Tenant ID}}/oauth2/token) to get access token getting the error
Access to XMLHttpRequest at 'login.microsoftonline.com/.../token' from origin 'url.powerappsportals.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Tried: Created a site setting inside the customer portal but same error.

Code:
function Token() {
var tenantID = "Tenant ID";
var client_id = "Client ID";
var client_secret = "Client Secret";
var resource = "">target.crm.dynamics.com";
$.ajax({
async: true,
crossDomain: true,
//"dataType": "json",
url: "">login.microsoftonline.com/" + tenantID +"/oauth2/token",
method: "POST",
headers: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
"grant_type": "client_credentials",
"client_id ": client_id, //Provide your app id
"client_secret": client_secret, //Provide your client secret genereated from your app
"resource ": resource
},
success: function (response) {
console.log(response);
token = response.access_token;
alert(token);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
})
}
Please help me how to resolve this issue or I am executing the webapi in wrong manner.
Thanks!