I have a WCF service that will be using basic authentication and would like to be able identify "who" is trying to use the service. I know that the HttpContext.Current is NULL and in the WCF service, but do not know what the alternative is to get the username.
userName = HttpContext.Current.Request.ServerVariables["LOGON_USER"];
To make authentication of WCF service more secure use server certificate for authentication. If certificate is available include it in WCF server otherwise we can also create self-signed certificate from IIS.
To configure a service to authenticate its clients using Windows Domain username and passwords use the WSHttpBinding and set its Security. Mode property to Message . In addition you must specify an X509 certificate that will be used to encrypt the username and password as they are sent from the client to the service.
Negotiate authentication automatically selects between the Kerberos protocol and NTLM authentication, depending on availability. The Kerberos protocol is used if it is available; otherwise, NTLM is tried. Kerberos authentication significantly improves upon NTLM.
Something like this maybe?
string login = OperationContext.Current
.ServiceSecurityContext
.PrimaryIdentity
.Name;
Obviously it helps to check for null reference exceptions along that path but you get the idea.
OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With