Skip to content

Commit

Permalink
Added additional logic for Azure Functions to use DefaultAzureCredential
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed Feb 17, 2023
1 parent b876ed9 commit 64f67bc
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,22 @@ public static IServiceCollection AddMassTransitForAzureFunctions(this IServiceCo
var connectionString = config[connectionStringConfigurationKey];

if (string.IsNullOrWhiteSpace(connectionString))
throw new ArgumentNullException(connectionStringConfigurationKey, "A connection string must be used for Azure Functions.");
{
var ns = config["ServiceBusConnection__fullyQualifiedNamespace"]
?? config[$"{connectionStringConfigurationKey}__fullyQualifiedNamespace"];
if (string.IsNullOrWhiteSpace(ns))
{
throw new ArgumentNullException(connectionStringConfigurationKey,
"The service bus connection string or namespace was not configured");
}

connectionString = $"Endpoint=sb://{ns}";
}

cfg.Host(connectionString, h =>
{
if (IsMissingCredentials(connectionString))
h.TokenCredential = new ManagedIdentityCredential();
h.TokenCredential = new DefaultAzureCredential();
});

cfg.UseServiceBusMessageScheduler();
Expand Down

0 comments on commit 64f67bc

Please sign in to comment.