web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

CORS error occurred during the token retrieval process from Power pages

(0) ShareShare
ReportReport
Posted on by 700
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!
 
I have the same question (0)
  • Suggested answer
    Likith Profile Picture
    4 on at
    Hello,

    It seems like you're encountering a CORS (Cross-Origin Resource Sharing) issue when attempting to execute CRM operations from a Power Page on an external website.

    Considering the information in Manage your site's Content Security Policy | Microsoft Learn, you can follow below steps to address the issue:
     
    • In the Portal Management app, under Site Settings, review the 'HTTP/Content-Security-Policy' settings. Make sure the 'script-src' directive includes the domains you're making requests to. Adjust as needed to allow communication with 'login.microsoftonline.com'.
    • HTTP/Access-Control-Allow-Origin: User URL of the Microsoft Dataverse instance, such as https://contoso.crm.dynamics.com. To allow any URI to access your resources, use *. 
      This setting controls which domains are allowed to make requests to your Power Pages site. If you want to allow any URI to access your resources, you can set the value to '*'. (
      Set up HTTP headers in Power Pages | Microsoft Learn).

    ​​​​​​​Best regards,
    Likith Khareedu

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 41 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 39

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans