我正在尝试通过 Azure DevOps 管道自动化 api 测试,并且设置了一些似乎不起作用的 bruno 配置。 OAuth2 通过 Azure EntraID 中的应用程序注册进行设置。这是我的布鲁诺配置:
收藏.bru
auth {
mode: oauth2
}
auth:oauth2 {
grant_type: client_credentials
access_token_url: https://login.microsoftonline.com/***/oauth2/v2.0/token
client_id: ***
client_secret: ***
scope: https://graph.microsoft.com/.default
}
script:post-response {
var token = res.body.access_token;
console.log(res.body)
console.log('Access Token:', token); // Debug log
if (token) {
bru.setVar('oauth2_token', token)
} else {
console.log('Token retrieval failed.'); // Log if token isn't retrieved
}
}
测试.bru
meta {
name: Backend Api Test
type: http
seq: 2
}
get {
url: https://my-app.com/api
body: none
auth: oauth2
}
此配置似乎在我的管道中不起作用,在本地测试时也不起作用。我收到 401 未经授权的错误。但是,当我从 bruno 桌面运行此请求时,我收到 200 响应并且它按预期工作。运行的输出如下所示:
Backend (401 Unauthorized) - 205 ms
{}
Access Token: undefined
Token retrieval failed.
我在这里做错了什么?似乎当我在布鲁诺桌面之外和管道中本地运行它时,它不起作用。如有任何帮助,我们将不胜感激。
您在 Azure DevOps 上构建它而不使用 Postman 或 qodex 等任何无代码工具有什么具体原因吗?