的AuthenticationFailedInvalidHead

的AuthenticationFailedInvalidHead

本文介绍了使用Azure API管理REST API时的AuthenticationFailedInvalidHeader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿意使用策略将Azure Api管理中的内容记录到eventhub中.

I'm willing to log stuff from my Azure Api Management into an eventhub using policies.

我正在遵循此文档: https://docs.microsoft.com/en-us/rest/api/apimanagement/logger/createorupdate

这是我的HTTP请求(使用邮递员):

Here is my HTTP Request (using Postman):

PUT /subscriptions/3f0a0802-0a42-4a73-82b2-094d41acd70a/resourceGroups/GRP-Poc-BilanHydrique/providers/Microsoft.ApiManagement/service/WaterBalance/loggers/end-user-logger?api-version=2017-03-01 HTTP/1.1
Host: management.azure.com
Authorization: {my token}
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 449f686d-3a86-b714-0b37-979567f6f921

{
  "properties": {
    "loggerType": "azureEventHub",
    "description": "adding a new logger",
    "credentials": {
      "name": "api-management-logs",
      "connectionString": "{my connection string}"
    }
  }
}

我从Api Manager用户界面通过以下URL生成了令牌:/admin/tenant/access我已经检查了到期时间.

I generated my token from the Api Manager UI at this URL : /admin/tenant/accessI've checked the expiration.

它看起来像这样:

SharedAccessSignature integration&{date}&{base64stuff}==

这是我创建令牌的屏幕截图:屏幕截图

Here is a screenshot of where I created that token :screenshot

在这里,您会得到答复:

And here you have the response :

{
"error": {
    "code": "AuthenticationFailedInvalidHeader",
    "message": "Échec de l'authentification. L'en-tête 'Authorization' est fourni dans un format incorrect."
}

我不知道发生了什么.有任何想法吗 ?有解决方法吗?有什么方法可以通过azure门户创建api管理记录器?

I can't figure out what's going on. Any ideas ?Is there a workaround ? Is there any way to create the api management logger through the azure portal ?

谢谢!

更新01/30:

感谢您的回答,我发现这不是正确的API.我尝试了API Management端点,但收到500 HTTP错误:

Thanks to your answers, I figured out it was not the right API.I've tried the API Management endpoint, and I get a 500 HTTP error :

请求:

PUT /loggers/end-user-logger?api-version=2018-01-01 HTTP/1.1
Host: waterbalance.management.azure-api.net
Authorization: SharedAccessSignature integration&201801301710&{secret}==
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 2618737b-af3e-c7d3-1d31-6b6f654100e9

{
  "properties": {
    "loggerType": "AzureEventHub",
    "description": "adding a new logger",
    "credentials": {
      "name": "end-user-logs",
      "connectionString": "Endpoint=sb://api-management-logs.servicebus.windows.net/;SharedAccessKeyName=Sending;SharedAccessKey={secret}"
    }
  }
}

响应:

     {
    "error": {
        "code": "InternalServerError",
        "message": "Request processing failed due to internal error.",
        "details": null
    }

这似乎不是令牌问题,因为我没有收到未经授权的错误.

It doesn't seem to be a token issue since i don't get a Unauthorized error.

推荐答案

您使用的API PUT /subscriptions/3f0a0802-0a42-4a73-82b2-094d41acd70a/resourceGroups/GRP-Poc-BilanHydrique/providers/Microsoft.ApiManagement/service/WaterBalance/loggers/end-user-logger?api-version=2017-03-01 HTTP/1.1是Azure Rest APi,而不是API Management API.

The API PUT /subscriptions/3f0a0802-0a42-4a73-82b2-094d41acd70a/resourceGroups/GRP-Poc-BilanHydrique/providers/Microsoft.ApiManagement/service/WaterBalance/loggers/end-user-logger?api-version=2017-03-01 HTTP/1.1 you used is a Azure Rest APi, not API Management API.

对于 Azure Rest API ,您需要创建一个服务主体,然后使用它来创建令牌.

For Azure Rest API, you need create a service principal then use it to create a token.

调用API时,标头为Authorization: Bearer $token

When you call the API, the header is Authorization: Bearer $token

有关此的更多信息,请参见类似的问题.

More information about this see this similar question.

这篇关于使用Azure API管理REST API时的AuthenticationFailedInvalidHeader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:55