Thursday, February 28, 2008

WCF Impersonation With Client

If you have a service that uses Windows authentication and you want to impersonate the caller you need to configure the client and the server.

This is the client proxy. You need to give it the correct credentials.

client.ClientCredentials.Windows.ClientCredential.Domain = "DOMAINName";
client.ClientCredentials.Windows.ClientCredential.UserName = "UserName";
client.ClientCredentials.Windows.ClientCredential.Password = "Password";
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;


The server side looks like this:



using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
...
}


This impersonate part of the method. This property impersonate all method:



[OperationBehavior(Impersonation = ImpersonationOption.Required)]

No comments: