Looking for a little advice (or maybe even a direct answer).
I have an MVC3 website. I also have a set of WCF services running (for now everything is on the same box).
What I'm trying to do is authenticate the client (that part is working fine), then pass that authenticated user on to various WCF calls.
At the moment I've hooked up the Application_AuthenticateRequest()
method in Global.Asax
, which boils down to creating a new GenericIdentity & GenericPrincipal
, then assigning that principal to HttpContext.Current.User
:
...
GenericIdentity identity = new GenericIdentity(userName);
GenericPrincipal principal = new GenericPrincipal(identity, null);
HttpContext.Current.User = principal;
...
And that part seems to be working fine as well.
But when I hit my service, I have completely lost the user that I set. The values are empty or false.
The one main thing I've noticed is that on the Client side, the HttpContext.Current.User.Identity
object is of type {System.Web.Security.FormsIdentity}
, but in the service it's of type {System.Security.Principal.WindowsIdentity}
.
Based on some of what I've read, it sounds like simply modifying my web.config
so it contains aspNetCompatibilityEnabled="true"
may be enough to make this work properly. But that's not what I'm seeing. So either I'm not understanding everything (a very good possibility) or I've got something screwed up (another good possibility).
So my question. Is this even possible, and if so - thoughts on what I'm missing? I notice a few others have posted something similar but have never quite received a definite answer (see here and here).
Any suggestions are very much appreciated.
I can't really answer directly to your question but hopefully will help you find the definite answer.
You have 2 service layers, and seems your requirement is to share Authentication identity among all layers.
So, in principle, you'd need (at least) the same Authentication mechanisms or algorithms or techniques to achieve this. But at this point you are not using the same (and you noticed when you saw a FormsIdentity
and a WindowsIdentity
there).
Facts:
Problems:
So... being unaware of your requirements, I would first suggest you:
I've seen this running many times by now. Not having authentication on a private service is a good performance deal, but you need to take precautions cause in general, most of the IT attacks come from the internal LAN.
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