【问题标题】:Authentication information is not given in the correct format. Check the value of Authorization header in Azure Ratecard Apis验证信息的格式不正确。检查 Azure Ratecard API 中 Authorization 标头的值
【发布时间】:2018-10-22 20:10:23
【问题描述】:

要获取价目表,我使用的是下面的 api。

https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&$filter=OfferDurableId+eq+{offer-id}+and+Currency+eq+'USD'+and+Locale+eq+'en-US'+and+RegionInfo+eq+'IN'

我在请求中传递了值为“Bearer eyioe ...”的授权标头。 它之前工作过,但最近得到以下响应

<?xml version="1.0" encoding="utf-8"?>
<Error>
    <Code>InvalidAuthenticationInfo</Code>
    <Message>Authentication information is not given in the correct format. Check the value of Authorization header.
RequestId:5dc4ea49-b01e-00f9-6760-dcfb83000000
Time:2018-04-25T06:42:45.8106146Z</Message>
</Error>

【问题讨论】:

  • 我不确定,请检查您请求中的content type 是否为application/json
  • 您是如何获得访问令牌的?
  • @WayneYang-MSFT 内容类型没有帮助。令牌是使用 adalj4 库获取的
  • 我也有同样的问题。在 Postman 中工作,但不在 C# 应用程序中工作。使用完全相同的不记名令牌和标头。

标签: azure azure-active-directory


【解决方案1】:

可能的情况是 RateCard API 正在发回 302 重定向。在这个问题出现时,新版本中对此进行了更改。

建议的解决方法是:

  1. 获取不记名令牌,
  2. 向 ARM 发出请求,并将 Authentication Header 设置为不记名令牌(这与以前相同)
  3. RateCard 将返回一个 302 状态代码,该代码表示​​重定向并包含第二个 URL,可从中获取价目表(这是新的)。
  4. 必须向第二个 URL 发出第二个请求。请注意,许多 http 库会自动跟随重定向并为您发出第二个请求。发出第二个请求时,需要删除包含不记名令牌的授权标头,如果没有,您将看到错误。如何在您的代码中实际实现这将取决于您使用的 http 客户端。对于 C#,代码如下:

const string subId = "Subscription Id here";
const string token = "Auth Token here.";

const string offer = "MS-AZR-0003P";
const string currency = "USD";
const string locale = "en-US";
const string region = "US";

using (var rateCardClient = new HttpClient() { BaseAddress = new Uri("https://management.azure.com/") })
{
    rateCardClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);
    var response = await rateCardClient.GetAsync($"subscriptions/{subId}/providers/Microsoft.Commerce/RateCard?api-version=2016-08-31-preview&$filter=OfferDurableId eq '{offer}' and Currency eq '{currency}' and Locale eq '{locale}' and RegionInfo eq '{region}'");

    Console.WriteLine($"StatusCode:{response.StatusCode}");
    var ratecard = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

    Console.Write(ratecard);
}

有关更多信息,请参阅此 Github 问题页面: https://github.com/MicrosoftDocs/azure-docs/issues/7423

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-12
    • 2020-08-01
    • 2018-09-01
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 2014-03-18
    相关资源
    最近更新 更多