Search code examples
c#.netwindowsauthenticationpass-through

Implement Pass-Through Authentication in C#


I am developing a TcpClient/TcpListener based client-server application. Now I have come to the point where I need to authenticate the user. I could use the PrincipalContext-Class on the server side and request username/password/domain from the client, but I don't want to send the credentials over the network. Additionally, I don't want to ask the user for their credentials again. So, I know the Citrix Receiver which supports pass-through authentication. It uses the current logged on user and does not request any credentials and authenticates the user against the server. It just works.

How can I do this in my application? I thought about some kind of token which can be sent to the server, but I could not find any solution.


Solution

  • Wrap the NetworkStream in a NegotiateStream, and call the appropriate NegotiateAs... methods on both client and server.

    The client can specify what impersonation level to allow, and the server can specify what level it requires (minimally Identification in order to determine client identity, but if you need to access local or network resources as the client, you could also specify Impersonation or, with the right network configuration, Delegation).

    Once authenticated, the server can determine the client's identity and/or impersonate using the NegotiateStream's RemoteIdentity property.

    As I mentioned in my comment, I don't know how Citrix affects this setup (never having used it), but if it's basically completely transparent to the application and everything uses standard Windows credentials, then this should work.