4

I have a Web API application which I'm protecting with Windows Authentication (locally, it'll translate to AD in the production environment). I just started adding features that rely on authentication and/or getting properties of the current user, and I immediately fell on a road block: the testing server doesn't seem able to authenticate.

How can I make the following test code send an authenticated request using Windows Authentication?

using (var server = Microsoft.Owin.Testing.TestServer.Create(MyApp.Startup.Configure)) {
    var response = server.HttpClient.GetAsync(url).Result;
    // Assert things about the response
}
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
  • Interesting, do you get the response in your example as if no authentication had ever been implemented? – Anish Patel Jul 24 '15 at 17:19
  • @AnishPatel: If I remove the authorization requirement from the action I'm testing, it works as long as I don't try to access the current user (if I do, I get an exception, since there is none...). With the auth requirement, I get a 401 (just as I want for an unauthorized request). What I need, is to be able to authenticate (or mock the authentication of) a Windows user through the testing server. – Tomas Aschan Jul 27 '15 at 06:55
  • I know is late but for future problems, this worked for me: https://stackoverflow.com/a/24714361/5147720 – Jose Jul 01 '19 at 09:03

0 Answers0