Posted on 05/01/2019 05:56:45
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