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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Call D365FO Service gives (401) Unauthorized error.

(0) ShareShare
ReportReport
Posted on by 4,075

I am trying to get the code from the ServiceSample application from github to work, more specifically the JsonConsoleApplication code.

I have made the App Registration on Azure, and registered the application on the "Azure Active Directory applications" page in D365FO.

I changed these values in the ClientConfiguration.cs file, so they should be correct.

UriString = "https://[myazureserver].cloudax.dynamics.com/"
ActiveDirectoryResource = "https://[myazureserver].cloudax.dynamics.com"
ActiveDirectoryTenant = "login.windows.net/dev.onmicrosoft.com"
ActiveDirectoryClientAppId = "[Should be the right one from Azure]"
ActiveDirectoryClientAppSecret = "[Should be the right one from Azure]"

And in Program.cs line 25 i added the parameter true to GetAuthenticationHeader so it should use web authentication.

Now when I run the program i get the error "The remote server returned an error: (401) Unauthorized." in line 29 "using (var response = (HttpWebResponse)request.GetResponse())"

If I look at the Event Viewer under Dynamics / AX-WebApi I see this error "Web API Owin Authentication Configuration Missing Error", but I have no clue what that means.

Can anyone help me get this to work?

I have the same question (0)
  • Suggested answer
    Ajit Profile Picture
    8,755 on at
    RE: Call D365FO Service gives (401) Unauthorized error.

    Verify you Active Directory Tenant , you can check from Azure portal - portal.azure.com/

  • Rudi Hansen Profile Picture
    4,075 on at
    RE: Call D365FO Service gives (401) Unauthorized error.

    Just exactly do i need from the Tenant?

    Are you referring to the value in ActiveDirectoryTenant, with I have set to "login.windows.net/dev.onmicrosoft.com" (Sorry corrected the error in my exiting post)

    But I see nothing but a Tenant ID on the Azure Portal, and that is a string not an url.

  • Verified answer
    Ajit Profile Picture
    8,755 on at
    RE: Call D365FO Service gives (401) Unauthorized error.

    This blog might help you to get values from portal - www.axpulse.com/.../

  • Rudi Hansen Profile Picture
    4,075 on at
    RE: Call D365FO Service gives (401) Unauthorized error.

    YES Finally Hurrah :-D

    It has really been bothering me that I have not been able to solve this problem with the exiting guides I have so far been able to find.

    But the solution was then to replace my :

    ActiveDirectoryTenant = "login.windows.net/dev.onmicrosoft.com

    With :

    ActiveDirectoryTenant = "login.microsoftonline.com/[TenantId]/saml2"

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 765 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 743

#3
Sumit Singh Profile Picture

Sumit Singh 551

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans