如何管理 Azure EventGrid 授权方案?

How to manage Azure EventGrid Authorization Scheme?

我正在尝试 post C# 中的事件,但收到有关授权方案的错误。

我正在 Azure 的应用服务中的 Web 作业中执行代码。 这是给我带来问题的代码:

Using Microsoft.Azure.EventGrid;

var eventGridClient = new EventGridClient(credentials);
client.PublishEventsAsync(topicHostname, events).Wait();

我得到的错误是这样的:

Microsoft.Rest.Azure.CloudException: Request has an unsupported Authorization scheme:Bearer. Authorization scheme must be SharedAccessSignature.

我在哪里可以管理它?

从报错信息来看,您使用的凭证有误,应该是如下代码。

string topicEndpoint = "https://<topic-name>.<region>-1.eventgrid.azure.net/api/events";
string topicKey = "<topic-key>";
string topicHostname = new Uri(topicEndpoint).Host;

TopicCredentials topicCredentials = new TopicCredentials(topicKey);
EventGridClient client = new EventGridClient(topicCredentials);
client.PublishEventsAsync(topicHostname, events).Wait();

参考 - https://docs.microsoft.com/en-us/dotnet/api/overview/azure/eventgrid#publish-events