I'm trying to post an Event in C#, but getting an error regarding the authorization scheme.
I'm executing the code in a webjob in an app service in Azure. This is the code giving me problems:
Using Microsoft.Azure.EventGrid;
var eventGridClient = new EventGridClient(credentials);
client.PublishEventsAsync(topicHostname, events).Wait();
The error I get is this:
Microsoft.Rest.Azure.CloudException: Request has an unsupported Authorization scheme:Bearer. Authorization scheme must be SharedAccessSignature.
Where can I manage this?
From the error message, you are using the wrong credential, it should be the code like below.
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();
Reference - https://docs.microsoft.com/en-us/dotnet/api/overview/azure/eventgrid#publish-events
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.