【发布时间】:2017-06-03 09:52:17
【问题描述】:
我有一个使用 OAuth 2.0 进行授权的 ASP.NET Web API 2。假设我有一个简单的 Web API 方法,例如:
GET: http://host/api/profiles/user123 (requires OAuth 2.0 token)
所以,使用Postman,很容易测试这个 Web API。我从 Web API OAuthAuthorization 方法中获得了 user123 的 OAuth 令牌,然后在 HTTP 请求的标头中使用该令牌:
GET /api/profiles/user123 HTTP/1.1
Host: {host}
Authorization: Bearer {Token}
Content-Type: application/json
Cache-Control: no-cache
但是,如果我保存我的测试并稍后运行它(由 Postman 本身或 Newman),令牌将在那时过期并且它不会工作。
如何使Newman 自动为user123 获取新令牌并在HTTP 请求中使用它?
注意:我知道如何使用 Postman 的 Authentication helpers 请求新令牌。但是这种情况不适合测试自动化。在测试自动化中,我想消除任何人工交互。
【问题讨论】:
标签: asp.net-web-api automated-tests asp.net-web-api2 postman newman