Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authenticating requests to Microsoft.Owin.Testing.TestServer

I'm using the owin TestServer class to unit test my web api. It's working great except that I'm unsure how to authenticate requests, so I can't really test endpoints that require authentication, other than to make sure that unauthenticated requests are unauthorized.

I am configuring WebApi to use only bearer token authentication as indicated here:

// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

Any ideas how I could do this easily?

like image 926
w.brian Avatar asked Nov 10 '13 16:11

w.brian


1 Answers

I found useful documentation to use TestServer+OAuth authentication
http://www.aaron-powell.com/posts/2014-01-12-integration-testing-katana-with-auth/

He also provides whole VS solution at GitHub.
https://github.com/aaronpowell/Owin.AuthenticatedTests/tree/a154931dd82e5180daf7163c2129f3a90401df55

like image 137
Youngjae Avatar answered Oct 14 '22 23:10

Youngjae