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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Custom Single Page App Authentication to OData Endpoint Calls

(0) ShareShare
ReportReport
Posted on by

What I'm trying to accomplish:

Create a custom, single-page web application that authenticates with Azure AD, gets a token, and then makes calls (javascript) to the OData endpoint in Dynamics 365 for Operations. Can this be done?

What I have tried:

  • Registered custom application in Azure AD and received client ID and set a reply URL
  • Created custom ASP .NET web application and added HTML and Script files.
  • Added reference to adal.js in my HTML page
  • Followed steps on how to authenticate with Azure AD and am successfully getting a valid token 
  • Sent "GET" request to Dynamics 365 for Operations OData endpoint including the bearer token in the xmlhttprequest header (code below)

What works:

  • When I run my application, I have a login button that redirects to the appropriate Azure AD login page
  • I am getting a valid token returned to my application page (I have deserialized the token and checked all of the values and they are all good)

What isn't working:

  • When I make a simple call to the Odata endpoint including a auth header with the bearer token, I am getting a 401, resource requires user authentication error.

What might be the issue here?

code for the call here:

function retrieveProjects(error, token) {
    // Handle ADAL Errors.
    if (error || !token) {
        errorMessage.textContent = 'ADAL error occurred: ' + error;
        return;
    }

    var req = new XMLHttpRequest()
    req.open("GET", encodeURI(organizationURI + "/data/Projects"), true);
    //Set Bearer token
    req.setRequestHeader("Authorization", "Bearer " + token);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    
    
    req.onreadystatechange = function () {
        if (this.readyState == 4 /* complete */) {
            req.onreadystatechange = null;
            if (this.status == 200) {
                var projects = JSON.parse(this.response).value;
                renderProjects(projects);
            }
            else {
                var error = JSON.parse(this.response).error;
                console.log(error.message);
                errorMessage.textContent = error.message;
            }
            console.log(req.responseText);
        }
    };
    req.send();
}

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Thanks for the reply, Sukrut. My goal is to have a single page web app, and use JavaScript to make the calls, by first acquiring the token using adal.js. What is the path you are using though (/api/services)?

  • Community Member Profile Picture
    on at

    OK, thanks. I believe my issue is that the token I'm acquiring through adal.js has my client ID and user credentials, but there does not seem to be a parameter for including a client secret in the wrapper. So I'm thinking that if I just cut out using adal.js and write vanilla js, including my client secret in the token request, that it will work. I will report back if I get it working.

  • Valery Moskalenko Profile Picture
    78 on at

    Try to register your app in Azure AD and then create a record in D365Op System administration --> Setup --> Azure Active Directory applications. Use your App guid as client id.

  • Verified answer
    Community Member Profile Picture
    on at

    Thank @Valery - yes, I have done that. Another person had this issue as well and has opened a ticket with Microsoft. The issue is actually on Microsofts side and it is because they are not allowing CORS on the D365 server. You can actually change the server settings in a dev environment and then this will work. Apparently, support for JavaScript against the OData endpoint is being worked on and is slated for an upcoming release - though no actual timeline was communicated. Ping back to post here: github.com/.../28

  • Valery Moskalenko Profile Picture
    78 on at

    Thanks! Yes, it's an issue.

    Well, as a workaround you may use some kind of proxy. You may create Azure LogicApp/Flow based on HTTP trigger that gets the data from D365Op and sends JSON in respond.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans