无法重复有关如何在 Postman 上获取 OAuth2.0 访问令牌的步骤

Cannot repeat steps on how to get OAuth2.0 Access Token on Postman

在 Postman 上,我可以通过提供回调 URL、auth URL 和客户端 ID 来获取 OAuth2.0 的新访问令牌。

我想在 JMeter 上分解这个任务,因为我在那里找不到这个函数。我的理解是分为认证->授权->回调

当我在 JMeter 上使用 HTTP(S) Test Script Recorder 时,我得到了上面提到的三个动作。当我重新运行它们时,它在 Authenticate 部分告诉我这个错误:<oauth><error_description>Full authentication is required to access this resource</error_description><error>unauthorized</error></oauth>.

为了确定这不是我使用的程序的问题,我在 Postman 上做了,也发现了这个错误。

我想知道如何将 OAuth2.0 获取新访问令牌 功能分解为基本 API 设置,以便在 Postman 或 JMeter 上获取访问令牌。

不要比较这些工具:

  • 邮递员是Electron application, it's basically a heavily customised Chromium web browser + NodeJS

  • 根据JMeter主页

    JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).

如果您可以使用 Postman 获取令牌,您只需添加 HTTP Header Manager to your JMeter Test plan and configure it to send Authorization header 和 Bearer YOUR_TOKEN_FROM_POSTMAN 的值,JMeter 应该会让您进入。

测试后发现Postman的OAuth 2.0 Get New Access Token弹出了目标URL的登录页面,需要填写用户名和密码,以便获得令牌。

当我尝试分解此登录所需的 API 时,它需要 https://yyyyy 的 GET 和 https://xxxxx/login 的 POST。点击 Send for POST,用户名和密码包含在表单数据中,然后点击 Send for GET。 GET 响应将包含此类令牌。

然而,仅将上述 GET 和 POST API 放入一个线程组中并不能在 JMeter 上工作。当我使用 HTTP(S) Test Script Recorder 无济于事时,我使用了 BlazeMeter 并意识到它正在使用 Transaction Controller 包含 1) GET of https://yyyyy 2) POST of https://xxxxx/login。有了这两个自上而下的安排,工作就成功了。令牌包含在 2).

的响应中

目前,这是我的发现,它回答了我的问题。 试试 BlazeMeter。