授权头缺失。

8
我遇到了这个错误:{"error":{"code":"AuthenticationFailed","message":"认证失败。缺少“Authorization”头。"}} 每当我尝试测试我的API时。
请问有人能建议如何在Postman或API Tester中设置身份验证头吗?API地址为:https://management.azure.com/subscriptions/{subscriptionID}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus?api-version=2019-03-01

4个回答

3

获取Bearer令牌以用于身份验证标头的简单方法是使用az cli

$token =  az account get-access-token | ConvertFrom-Json

然后通过访问$token.accesstoken,您将获得如下字符串。

enter image description here

您可以使用此令牌作为Bearer令牌调用API。

$headers = @{ Authorization = "Bearer $token.accesstoken" }

2

授权HTTP头的一部分,通常是Base64编码的令牌。在Postman中,您可以通过点击“Headers”按钮来添加它。

这是在Postman中设置授权的位置


2
您需要设置和配置Postman以获取Azure Active Directory令牌。
完整步骤请参见此处,以下是快速参考的屏幕截图。
文档中提供了一个示例令牌请求表单。 使用Postman获取令牌 令牌请求表单

1
这是使用curl获取https://medium.com/@mauridb/calling-azure-rest-api-via-curl-eb10a06127的指南。
您可以在此命令中替换占位符为您的服务主体。 curl -vX POST -d "grant_type=client_credentials&client_id=${spClientId}&client_secret=${spSecret}&resource=https%3A%2F%2Fmanagement.azure.com%2F" https://login.microsoftonline.com/${spTenantId}/oauth2/token)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接