Hi,
We have a requirement from our client for power pages. To fulfill the requirement we have created a custom action in Dynamics 365 CRM and tried to execute it from power pages (we have made as public website).
We attempted to perform CRM operations on a power page for an external website. To execute these operations, we need to obtain an authorization token. However, during the token acquisition process, we encountered a CORS error, as indicated below.
Access to XMLHttpRequest at 'https://login.microsoftonline.com/9dedbf2a-1967-42da-b7e3-24a5e2c16475/oauth2/token' from origin 'https://test-demo12345.powerappsportals.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
We are using the below code for the same.
var form = new FormData();
form.append(/grant_type/, /client_credentials/);
form.append(/client_id/, /Enter Client Id/);
form.append(/client_secret/, / Enter Client Secret /);
form.append(/resource/, /Enter CRM URL/);
var settings = {
/url/: https://login.microsoftonline.com/Enter Tenant Id/oauth2/token/,
/method/: /GET/,
/timeout/: 0,
/headers/: {
/Cookie/: /fpc=Avy3L6riZPxJsdXm9EXO0xI0P776AQAAALsnF90OAAAA; stsservicecookie=estsfd; x-ms-gateway-slice=estsfd/,
/Content-Type/: /application/jsonp/,
/Access-Control-Allow-Origin/: /*/,
/Access-Control-Allow-Methods/: /POST,GET,PUT/,
/Access-Control-Allow-Headers/: /Content-Type,X-Auth-Token,Origin,Authorization/,
},
/processData/: false,
/mimeType/: /multipart/form-data/,
/contentType/: false,
/credentials/: /include/,
/data/: form
};
$.ajax(settings).done(function (response) {
alert(response);
});
Note: It is working from postman.
Has anyone else encountered a similar issue and found a solution for it.
Thanks!