azure - Karate API 测试 - 承载错误 ="invalid_token",error_description ="The audience <number> is invalid"

标签 azure api token karate

Postman headers我正在使用 key 生成访问 token ,我将使用该 token 对我调用的 API 进行身份验证。问题是我收到错误:

状态代码为:401,预期:200 WWW-Authenticate:承载错误=“invalid_token”,error_description=“受众无效”

这就是我调用 API 的方式

Given url `https://login.microsoftonline.com/tenant_id/oauth2/token`
And form field grant_type = `client_credentials`
And form field client_id = `value`
And form field client_secret = `value`
When method post
Then status 200

match response.access_token != null

def access_token = response.access_token

print access_token

Given header Authorization = 'Bearer ' + access_token
Given url 'url'
And header accept = `plain/text`
And header 'X-Mimic-User' = `confidential`
When method GET
Then status 200

我希望使用生成的访问 token 对 API 进行身份验证。

最佳答案

看来您的错误可能与 Authorization header 有关,尽管错误描述很难破译,可能与范围相关?我会首先列出 URL,而不是 header ,除非您要重复使用它,并且想要为后续请求配置该值。设置 Bearer token 的另一种方法是:

And match response.access_token == '#present'

* def oauthToken = `Bearer ${response.access_token}`

但实际上,最重要的是检查您的请求,包括 header ,并在 Karate 和 Postman 之间进行比较,看看有什么不同。

关于azure - Karate API 测试 - 承载错误 ="invalid_token",error_description ="The audience <number> is invalid",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75247580/

相关文章:

ios - 如何使用 swift 等待登录 View 的 api 响应值

android - android gcm token 什么时候过期

azure - Bot 框架编写器无法发布到 Azure LUIS 错误

c# - 使用上传字段时 Azure 上的超时

c# - Azure Functions - 无法加载文件或程序集 '' AzureFunctions.Autofac.Shared'

python - 如何通过 API 创建带标题的 Imgur 相册?

api - 提升 REST 服务无法识别 PUT 请求

azure - azure WCF中继中超过64K时出现异常

azure - 列出 Azure blob 存储中不同目录的 blob

swift - 如何解码在 Swift 中收到 REST API 的 JWT token ?