azure - 使用托管标识对 Azure 服务总线进行经过身份验证的 REST API 调用

标签 azure azureservicebus azure-api-management azure-managed-identity

Azure 服务总线支持托管身份访问,但是我发现的向队列发送消息的唯一方法是使用这种需要代码和服务总线 SDK 的方法:

var tokenProvider = TokenProvider.CreateManagedServiceIdentityTokenProvider();
QueueClient sendClient = new QueueClient($"sb://{Config.Namespace}.servicebus.windows.net/", Config.Queue, tokenProvider);
await sendClient.SendAsync(new Message(Encoding.UTF8.GetBytes(messageInfo.MessageToSend)));
await sendClient.CloseAsync();

来源: https://github.com/Azure-Samples/app-service-msi-servicebus-dotnet https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-managed-service-identity

我正在寻找一种方法,通过 Azure API 管理策略中的 REST API 调用来执行相同的操作。我已授予 APIM、基于角色的对服务总线的访问权限,并且能够取回 token ,但在尝试使用授权 header 中传递的托管身份 token 进行 REST API 调用时,我从服务总线返回此错误:

MalformedToken: The credentials contained in the WRAP header are not well-formed.

看来服务总线目前可能仅支持 WRAP 或 SAS token 及其 REST API:https://learn.microsoft.com/en-us/rest/api/servicebus/send-message-batch

但是话又说回来,这在幕后是如何运作的呢?

TokenProvider.CreateManagedServiceIdentityTokenProvider()

看起来应该可以通过 REST API 实现。

最佳答案

在 SDK 中,他们似乎没有将其指定为 Authorization: Bearer tokenabcdef..... ,而是指定为 Authorization: tokenabcdef。这有点不寻常。

关于azure - 使用托管标识对 Azure 服务总线进行经过身份验证的 REST API 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58085164/

相关文章:

Azure APIM导入graphql api

azure - 当范围不是 Azure AD 中的图形 API 时,如何添加自定义声明并检索相同的声明作为 access_token 的一部分?

ubuntu - 如何删除使用 Meteor Up 创建的部署实例?

c# - Azure函数: limit the number of calls per second

azure - 在 Azure Function 中接收服务总线消息

azure - 我的 Azure 函数如何有选择地使用来自服务总线的消息?

Azure 数据工厂本地文件跳过标题行

ruby - 通过 Ruby 遏制的 Bing 搜索 API

azure-api-management - 在 Azure API 管理器中验证 POST 请求正文

azure - 无法在我部署的 Azure api 管理器内应用策略