Developer forum

Forum » Integration » How to Connect to Microsoft Dynamics 365 for Finance and Operations (on-premises) - Solution

How to Connect to Microsoft Dynamics 365 for Finance and Operations (on-premises) - Solution

Shiwanka Chathuranga
Shiwanka Chathuranga
Reply

Here i am going to explain the simple trick to connected to Microsoft Dynamics 365 for Finance and Operations (on-premises).

For this, we need to modify on the Dynamics365Connector.cs  in DynamicwebConnectorService

here is the current code to get authentication

private string GetAuthenticationHeader(NameValueCollection connectorSettings)
{
string activeDirectoryTenant = connectorSettings["ActiveDirectoryTenant"];
string activeDirectoryClientAppId = connectorSettings["ActiveDirectoryClientAppId"];
string activeDirectoryResource = connectorSettings["ActiveDirectoryResource"];
string activeDirectoryClientAppSecret = connectorSettings["ActiveDirectoryClientAppSecret"];
 
var credential = new ClientCredential(activeDirectoryClientAppId, activeDirectoryClientAppSecret);
 
AuthenticationContext authenticationContext = new AuthenticationContext(activeDirectoryTenant);
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(activeDirectoryResource, credential).Result;
 
return authenticationResult.CreateAuthorizationHeader();
}

In this code, we hit "Authority validation is not supported for this type of authority Parameter name: validateAuthority"

When you create AuthenticationContext it checking ValidateAuthority property as default, When we connect to On-Premises we need to disable that checking with a following code update 

AuthenticationContext authenticationContext = new AuthenticationContext(activeDirectoryTenant, false);

 

Hope this will help to you guys in future development

Thanks and Happy Coding


Replies

 
Nicolai Pedersen
Reply

Hi Shiwanka 

Thank you very much for sharing this - and sorry we could not help you on this one.

We will incorporate this in our code base.

BR Nicolai

 
Shiwanka Chathuranga
Shiwanka Chathuranga
Reply

Hi Nicolai

Don't Worry, I just share this as a help for other developers who need same kind of solution as your default not supporting.

Thanks

Shiwanka

 
Nicolai Pedersen
Reply

Just a heads up - this is now TFS#59176 and will be implemented in the first half of February.

Thanks, Nicolai

 
Shiwanka Chathuranga
Shiwanka Chathuranga
Reply

That's a Good news Nicolai

Thanks 

 

You must be logged in to post in the forum