英文:
The Authorization header is missing
问题
我遇到了这个错误:{"error": {"code": "AuthenticationFailed", "message": "认证失败。缺少 'Authorization' 标头。"}},每当我尝试测试我的 API 时,该 API 位于以下位置:
有人可以建议如何在 Postman 或 API Tester 中设置认证标头吗?
英文:
I am getting this error :{"error":{"code":"AuthenticationFailed","message":"Authentication failed. The 'Authorization' header is missing."}} whenever I am trying to test my API that is
Can anybody suggest a solution how to set authentication header in postman or API Tester.
答案1
得分: 3
获取用于身份验证标头的Bearer令牌的简单方法是使用az cli
。
$token = az account get-access-token | ConvertFrom-Json
然后通过访问$token.accesstoken
,您将获得如下所示的字符串。
您可以将此令牌用作API调用的Bearer
令牌。
$headers = @{ Authorization = "Bearer $token.accesstoken" }
英文:
An easy way to get a Bearer token in order to use for Authentication header would be to use az cli
.
$token = az account get-access-token | ConvertFrom-Json
Then by accessing $token.accesstoken
you will have string as shown below.
You can use this Token then with your API call as a Bearer
token
$headers = @{ Authorization = "Bearer $token.accesstoken" }
答案2
得分: 2
"Authorization"是HTTP标头
的一部分,通常是Base64编码的令牌。在Postman中,您可以通过单击“标头”按钮添加它。
英文:
Authorization
is the part of HTTP Header
and generally it is token which is Base64 encoded. In Postman, you can add it by clicking on "Headers" button.
答案3
得分: 2
你需要设置和配置Postman以获取Azure Active Directory令牌。
完整步骤可在此处找到 - 下面是快速参考的屏幕截图。
从文档中,这是一个示例令牌请求表单。
英文:
You need to set up and configure Postman to obtain an Azure Active Directory token.
A full walk though is covered here - screen shots below for quick reference.
From the docs - a sample token request form.
答案4
得分: 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
英文:
This is a guide to use curl
to get the https://medium.com/@mauridb/calling-azure-rest-api-via-curl-eb10a06127.
You can replace the place holder to your service principal in this command.
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论