We have a scenario where a WCF service is hosted on IIS. The authentication mode is WINDOWS. We are calling this WCF service from CRM plugin using windows authentication.
While getting the CRM organization instance, we are not getting windows user context.
private OrganizationDetail DiscoverOrganization(Uri discoveryUri, string organizationName, ClientCredentials lclClientCredentials)
{
DiscoveryServiceProxy serviceProxy;
using (serviceProxy = new DiscoveryServiceProxy(discoveryUri, null, lclClientCredentials, null))
{
IDiscoveryService service = serviceProxy;
var orgsRequest = new RetrieveOrganizationRequest()
{
AccessType = EndpointAccessType.Default,
Release = OrganizationRelease.Current,
UniqueName = organizationName
};
var organizations = (RetrieveOrganizationResponse)service.Execute(orgsRequest);
return organizations.Detail;
}
}
We tried setting credentials as below,
lclClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
lclClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
I don't think you can flow the Windows identity of the Dynamics client user to the web service this way. Dynamics plugins execute under one of three Windows accounts:
On top of this is layered the Dynamics (systemuser
) identity of the client user invoking the plugin, but not the Windows account. The Sandbox and Asynchronous services run in entirely separate processes from the web application, and likely have no way of knowing the Windows identity of the invoking user.
If the web service needs the CRM identity of the invoking user (in order to act as that user in CRM), you will need to:
systemuser
to the web service from the plugin.systemuser
account in those orgs.
systemuser
the Dynamics impersonation privilege, so it can act as other users.systemuser
GUID.