【发布时间】:2016-02-26 07:11:36
【问题描述】:
我有一个具有 owin 安全性的 .net web api 应用程序。安全中间件配置了 Google 身份验证(无本地用户名/密码身份验证)和 Oauth 持有者令牌。
在启动中:
public void ConfigureAuth(IAppBuilder app)
{
...
app.UseOAuthBearerTokens(new OAuthAuthnorizationServerOptions {
TokenEndpointPath = new PathString("/token"),
AuthorizeEndpointPath = new PathString("/account/authorize"),
Provider = new ApplicationOAuthProvider("web"),
...
});
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions {
ClientID = "...",
ClientSecret = "..."
});
}
从我的客户端应用程序我去
http://myapp.com/account/authorize?client_id=web&response_type=token&redirect_uri=...
这将重定向到用户填写的谷歌登录,然后返回我的应用程序,并使用我剥离的不记名令牌并添加到我的 api 的请求标头中。
我想编写一些集成测试,我的测试调用 API。测试具有测试用户的 google 凭据,但我不确定如何在不打开浏览器和 google 登录屏幕的情况下让测试进行身份验证。我可以用 Selenium 来驱动它,但这似乎很笨拙。
如何以编程方式获取不记名令牌以与我的 API 一起使用,以便我可以模拟我的测试用户?
【问题讨论】:
标签: authentication asp.net-web-api owin google-authentication