As part of an existing application that connects to our Dynamics 365 instance we are currently trying to modify our existing code at the recommendation of Microsoft based on article https://docs.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-office365-deprecation to utilize OAuth . The article provides a connection string example of:
connectionString = "AuthType=OAuth;Username=jsmith@contoso.onmicrosoft.com; Password=passcode;Url=contosotest.crm.dynamics.com;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d; RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Auto"
which allows me to successfully sign-in when I substitute our organization's Username and password however when I execute:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
using (var svc = new CrmServiceClient(conn))
{
Guid g = svc.ConnectedOrgId;
WhoAmIRequest request = new WhoAmIRequest();
WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);
Console.WriteLine("Your UserId is {0}", response.UserId);
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
The Organization ID that is returned is 00000000-0000-0000-0000-000000000000 and the response is a null object. I chalk this up to the use of the sample AppIDs. After substituting for our AppID and Organization url found in our instance settings however we're still getting the same results. Based on the information I've researched it appears our application needs to be registered in Azure AD. I'm utilizing information at https://docs.microsoft.com/en-us/powerapps/developer/data-platform/use-single-tenant-server-server-authentication however that appears to be for registering a new application. We're trying to add Azure AD for an existing Dynamics 365 application ported from an on-prem instance back in 2018. Is there any guidance for utilizing OAuth for older applications?
I think you are on the right track. You need the app registration, so you can give this app the consent to connect to your existing d365 environment.
Don’t forget to create an application user in d365 and ty it up to the azure app (client I’d)
Adis
136
Super User 2025 Season 1
Sohail Ahmed
81
Jonas "Jones" Melgaard
77
Super User 2025 Season 1