授权标头丢失

huangapple go评论88阅读模式
英文:

The Authorization header is missing

问题

我遇到了这个错误:{"error": {"code": "AuthenticationFailed", "message": "认证失败。缺少 'Authorization' 标头。"}},每当我尝试测试我的 API 时,该 API 位于以下位置:

https://management.azure.com/subscriptions/{subscriptionID}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus?api-version=2019-03-01

有人可以建议如何在 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

https://management.azure.com/subscriptions/{subscriptionID}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus?api-version=2019-03-01

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)

huangapple
  • 本文由 发表于 2020年1月3日 18:06:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576603.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定