Authenticating requests to Microsoft.Owin.Testing.TestServer

扶醉桌前 提交于 2020-01-13 07:48:11

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/19892190/authenticating-requests-to-microsoft-owin-testing-testserver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!