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/