Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Call D365FO Service gives (401) Unauthorized error.

(0) ShareShare
ReportReport
Posted on by 4,016

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?

  • Rudi Hansen Profile Picture
    Rudi Hansen 4,016 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"

  • Verified answer
    Ajit Profile Picture
    Ajit 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
    Rudi Hansen 4,016 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.

  • Suggested answer
    Ajit Profile Picture
    Ajit 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/

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans