This project has moved. For the latest updates, please go here.

How can I unit test OAuth2 authentication on Web API using Microsoft.Owin.Testing?

Oct 30, 2015 at 9:32 PM
Edited Oct 30, 2015 at 9:32 PM
Hi,

I have this VS solution setup:
MySolution
| -- WebApiProject
| -- UnitTestProject
I have installed the Microsoft.Owin.Diagnostics and Microsoft.Owin.Testing NuGet packages.

Now I want to test internal and external authentication using this set-up. How can I do this?

I have been googling this but can't find any documentation on how to apply TestServer here.

Thank you for enlightening me.
Coordinator
Nov 4, 2015 at 12:01 AM
Which OAuth2 components are you trying to test?
Nov 4, 2015 at 10:05 AM
Edited Nov 4, 2015 at 10:06 AM
At this time of reading I don't have the slightest idea as I'm right at the beginning of learning authentication with Web API. There is plenty of documentation for MVC but Web API doesn't even provide comments in the code. So I'm still striving for information.

Having some unit test I could create/use to see whether I'm following the right path (particularly in regard to expired tokens and using Refresh tokens) would be very helpful.
Coordinator
Nov 4, 2015 at 4:43 PM
Unit tests are for individual components, not entire applications flows.

This may help you get started: http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api
Nov 6, 2015 at 12:57 AM
Yes, I know. But that's not the question. The question is: How can I unit test a Web API endpoint from a separate unit test project?
Coordinator
Nov 6, 2015 at 5:42 PM
Nov 7, 2015 at 1:40 PM
That doesn't work with testing OAuth authentication.

Do you know about this framework: http://blogs.msdn.com/b/webdev/archive/2013/11/26/unit-testing-owin-applications-using-testserver.aspx
Coordinator
Nov 7, 2015 at 2:21 PM
Nov 7, 2015 at 3:45 PM
Exactly. And this project is my question about.
Coordinator
Nov 9, 2015 at 7:31 PM
Nov 9, 2015 at 10:06 PM
Would you mind just concentrating on my question or leave it to someone else to answer?