Azure connection with managed identity instead of connection string #416
Answered
by
zarusz
fp-hybrid-stani
asked this question in
Q&A
-
Hey guys, I would like to use Azure managed identity to connect to Azrue Service Bus, instead of connection string. Is it possible? Regards Stani |
Beta Was this translation helpful? Give feedback.
Answered by
zarusz
Jul 9, 2025
Replies: 1 comment 4 replies
-
Hey @fp-hybrid-stani, Yes, this should be possible using the builder.WithProviderServiceBus(cfg =>
{
// Do not set the connection string
// cfg.ConnectionString = serviceBusConnectionString;
cfg.ClientFactory = (svp, _) => new ServiceBusClient(
"<namespace>.servicebus.windows.net",
new DefaultAzureCredential() // or use ManagedIdentityCredential()
);
cfg.AdminClientFactory = (svp, _) => new ServiceBusAdministrationClient(
"<namespace>.servicebus.windows.net",
new DefaultAzureCredential() // or use ManagedIdentityCredential()
);
}); I haven't used MI yet, but this should do the trick. Let me know if it worked or not. If it did work, I can extend the Bus APIs so that its easier to configure the ASB transport when Managed Identity is used. Also, there is an Aspire sample in #343 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see there is a validation happening for the ConnectionString. As a workaround you could try to set some fake string in there. If the factory approach shared above works, I will issue a small feature to support the MI within the ASB bus configuration.