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/