Ricardo Jacobsen Thanks for posting your question in Microsoft Q&A. Based on my understanding, you are looking to retrieve primary or secondary keys by key name (not generate SAS token). Correct?
If so, you can use Namespaces - Authorization Rules - List Keys rest api with key name being authorization rule name in your client app. Make sure that identity you are using has permissions such as Microsoft.ServiceBus/namespaces/authorizationRules/listkeys/action
, Microsoft.ServiceBus/namespaces/authorizationRules/read
etc. (refer Microsoft.ServiceBus for full set of permissions) or you can assign built-in role such as Azure Service Bus Data Owner to the identity.
You can also retrieve it using Azure.Messaging.ServiceBus.Administration
package for managing entities in an existing namespace and here is the code snippet based on https://stackoverflow.com/a/65404170).
ServiceBusAdministrationClient client = new ServiceBusAdministrationClient(connectionString);
QueueProperties queue =await client.GetQueueAsync("myqueue");
var sasKey = queue.AuthorizationRules.FirstOrDefault(rule => rule.Name == "sasKeyName")?.PrimaryKey;
Check ServiceBusAdministrationClient class for other options such as TokenCredential
instead of ConnectionString
. For other languages, refer https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-management-libraries.
I hope this helps and let me know if any questions.
If you found the answer to your question helpful, please take a moment to mark it as Yes
for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.