Chatter.MessageBrokers.AzureServiceBus.Auth
3.2.0
See the version list below for details.
dotnet add package Chatter.MessageBrokers.AzureServiceBus.Auth --version 3.2.0
NuGet\Install-Package Chatter.MessageBrokers.AzureServiceBus.Auth -Version 3.2.0
<PackageReference Include="Chatter.MessageBrokers.AzureServiceBus.Auth" Version="3.2.0" />
<PackageVersion Include="Chatter.MessageBrokers.AzureServiceBus.Auth" Version="3.2.0" />
<PackageReference Include="Chatter.MessageBrokers.AzureServiceBus.Auth" />
paket add Chatter.MessageBrokers.AzureServiceBus.Auth --version 3.2.0
#r "nuget: Chatter.MessageBrokers.AzureServiceBus.Auth, 3.2.0"
#:package Chatter.MessageBrokers.AzureServiceBus.Auth@3.2.0
#addin nuget:?package=Chatter.MessageBrokers.AzureServiceBus.Auth&version=3.2.0
#tool nuget:?package=Chatter.MessageBrokers.AzureServiceBus.Auth&version=3.2.0
<a name="chatter-azureservicebus-auth"></a> Chatter.MessageBrokers.AzureServiceBus.Auth
Azure Active Directory (AAD) token-based authentication for the Chatter Azure Service Bus broker.
Overview
Chatter.MessageBrokers.AzureServiceBus.Auth lets the Chatter.MessageBrokers.AzureServiceBus broker authenticate to Azure Service Bus with Azure Active Directory access tokens instead of a connection-string shared-access key (SAS).
Instead of embedding a SharedAccessKey/SharedAccessSignature in the connection string, you supply a service-principal client ID (and a secret, certificate, or interactive redirect URI), or ask for an Azure managed identity outright. The package builds an Azure.Core.TokenCredential (e.g. a ClientSecretCredential, ClientCertificateCredential, InteractiveBrowserCredential, or ManagedIdentityCredential) and hands it to the Service Bus connection. When no explicit credential is supplied, it falls back to DefaultAzureCredential (managed identity, environment, Azure CLI, etc.), so the same code works locally and in Azure-hosted environments.
The package extends the ServiceBusOptionsBuilder exposed by the base broker — you opt in by calling one of the UseAadTokenProvider* extension methods. The base broker only applies the token provider when the configured connection string does not already contain a SAS token or key, so AAD auth is purely additive.
Installation
dotnet add package Chatter.MessageBrokers.AzureServiceBus.Auth
Getting Started
Enable AAD auth inside the AddAzureServiceBus options builder. Supply a connection string without a shared-access key (just the Endpoint), then call one of the UseAadTokenProvider* extensions:
using Chatter.MessageBrokers;
using Microsoft.Extensions.DependencyInjection;
services.AddChatter()
.AddAzureServiceBus(sb =>
{
// Endpoint only — no SharedAccessKey/SharedAccessSignature
sb.WithConnectionString("Endpoint=sb://my-namespace.servicebus.windows.net/");
// Authenticate with an AAD app registration + client secret
sb.UseAadTokenProviderWithSecret(
clientId: "00000000-0000-0000-0000-000000000000",
clientSecret: "<client-secret>",
authority: "https://login.microsoftonline.com/<tenant-id>/");
});
Four extension methods are available on ServiceBusOptionsBuilder:
UseAadTokenProviderWithSecret(clientId, clientSecret, authority, optBuilder = null)— authenticate as a confidential client using a client secret.UseAadTokenProviderWithCert(clientId, thumbPrint, authority, optBuilder = null, validCertsOnly = true)— authenticate using a client certificate located by thumbprint in theCurrentUser/LocalMachineMystore. SetvalidCertsOnly: falsefor self-signed certs.UseAadTokenProviderInteractively(clientId, redirectUri, optBuilder = null)— authenticate via an interactive flow using the supplied redirect URI.UseAadTokenProviderWithManagedIdentity(clientId = null, optBuilder = null)— authenticate as an Azure managed identity. Pass the client ID of a user-assigned managed identity, or omit it (or pass null/whitespace) for the system-assigned identity.
Managed identity
To authenticate as an Azure managed identity, use the managed-identity mode:
// User-assigned managed identity
sb.UseAadTokenProviderWithManagedIdentity(clientId: "<user-assigned-mi-client-id>");
// System-assigned managed identity — omit the client id
sb.UseAadTokenProviderWithManagedIdentity();
This mode returns a ManagedIdentityCredential whose identity is the client ID you passed. It never consults the DefaultAzureCredential chain, so no other credential source — an environment-backed service principal, a developer's az login session — can answer in the managed identity's place. AZURE_TOKEN_CREDENTIALS and the Exclude* credential flags have no effect here, because there is no chain for them to narrow.
A null or whitespace clientId asks for the system-assigned managed identity. One caveat: on a federated-token host (for example AKS workload identity), the Azure SDK's token-exchange managed-identity source falls back to the AZURE_CLIENT_ID environment variable when no identity was supplied, so the blank case authenticates as the platform-bound workload identity rather than literally system-assigned. Passing a client ID explicitly avoids that fallback entirely.
This credential fails loudly off Azure. With no managed-identity endpoint reachable, token acquisition raises CredentialUnavailableException instead of quietly falling through to another credential — and it may take a noticeable moment to surface, since the SDK's IMDS probe timeout for this path is internal and not caller-tunable. That is the intended trade: on the previous chained behavior a developer machine silently authenticated as the developer rather than as the managed identity, and the failure only appeared once something depended on the managed identity's role assignments. To keep one code path across environments, switch modes by environment — the managed-identity mode in Azure, and one of the DefaultAzureCredential fallbacks below locally, which still honor az login:
if (env.IsDevelopment())
{
// Blank redirect URI falls back to DefaultAzureCredential, which picks up `az login`
sb.UseAadTokenProviderInteractively(clientId: "<app-client-id>", redirectUri: null);
}
else
{
sb.UseAadTokenProviderWithManagedIdentity(clientId: "<user-assigned-mi-client-id>");
}
Named argument required for
optBuilder-only calls.optBuilderconfiguresManagedIdentityCredentialOptions, whose most useful settable member is the inheritedAuthorityHost(for sovereign clouds); it cannot redirect the identity, because the SDK'sManagedIdentityIdproperty is internal and get-only. The first parameter isstring clientId, so a bare lambda in the first positional slot is a compile error. Write it as:sb.UseAadTokenProviderWithManagedIdentity( optBuilder: opts => opts.AuthorityHost = new Uri("https://login.microsoftonline.us/"));
Default credential fallback
If the credential argument (clientSecret / thumbPrint / redirectUri) is null or whitespace, the secret, certificate, and interactive modes fall back to DefaultAzureCredential and resolve the identity ambiently from host state. This is the package's only ambient path, and the one that honors az login — which makes it the local-development counterpart to the managed-identity mode above. Use the optional optBuilder delegate to configure DefaultAzureCredentialOptions for that fallback:
sb.UseAadTokenProviderInteractively(
clientId: "00000000-0000-0000-0000-000000000000",
redirectUri: null, // fall back to DefaultAzureCredential
optBuilder: opts => opts.ExcludeAzureCliCredential = true);
How It Works
- AAD Token Credential — every extension method ultimately produces an
Azure.Core.TokenCredential. This is registered on the builder viaServiceBusOptionsBuilder.AddTokenProvider(Func<TokenCredential>). The factory delegate is invoked eagerly at registration time —AddTokenProvidercallstokenCredentialFactory?.Invoke()immediately rather than deferring construction until the options are built. A practical consequence: when usingUseAadTokenProviderWithCert, the X509 certificate store is read at registration time, not at first token acquisition. AadTokenProviderFactory— created withAadTokenProviderFactory.Create(clientId), the factory exposesWithSecret(...),WithCert(...),WithInteractive(...), andWithManagedIdentity(...), each returning aTokenCredential(ClientSecretCredential,ClientCertificateCredential,InteractiveBrowserCredential, orDefaultAzureCredentialon fallback).WithManagedIdentity(...)is the only method that returns none of those — it constructs aManagedIdentityCredentialdirectly, so it is also the only method that never involves theDefaultAzureCredentialchain.- Token acquisition — for explicit credentials the factory constructs the corresponding
Azure.Identitycredential type directly.WithSecret(...)andWithCert(...)parse the tenant ID and authority host out of the suppliedauthorityURL (the tenant ID is the first non-empty path segment and any deeper segments are ignored, so both a bare directory URL of the formhttps://login.microsoftonline.com/<tenant-id>/and the/v2.0-suffixed issuer URL the Azure portal hands out are accepted; the scheme+host becomesAuthorityHost) and build aClientSecretCredentialorClientCertificateCredential; for the certificate path the cert is resolved from the X509Mystore (CurrentUser, thenLocalMachine) by thumbprint, throwing if not found. Because the first segment is taken as-is, any authority whose first segment is not the tenant ID — a non-AAD routing prefix such as Azure AD B2C's/tfp/<tenant>/<policy>, ADFS, or DSTS, or a malformed AAD URL that omits the tenant (e.g. a pasted/oauth2/v2.0/tokenendpoint) — resolves to a well-formed but wrong tenant ID, so the credential constructs and the misconfiguration surfaces at first token acquisition rather than at credential construction. The credential still carries the client ID and the secret or certificate you supplied; what a request made with a wrong tenant ID yields at token acquisition is decided by Microsoft Entra, and this package makes no guarantee about that outcome.WithInteractive(...)takes noauthority— it builds anInteractiveBrowserCredentialfromInteractiveBrowserCredentialOptionscarrying onlyClientIdandRedirectUri, so the interactive path is not tenant-scoped by an authority value. When no explicit credential is provided, it returns aDefaultAzureCredential.WithManagedIdentity(...)takes noauthorityeither — it resolves the factory's client ID to aManagedIdentityId(FromUserAssignedClientId, orSystemAssignedwhen the client ID is null or whitespace), hands that toManagedIdentityCredentialOptions, invokes the caller'soptBuilder, and constructs aManagedIdentityCredential. The identity travels on the credential itself rather than being selected from a chain, sooptBuildercan adjust transport settings such asAuthorityHostbut cannot change which identity is requested. - Connection wiring — during
ServiceBusOptionsBuilder.Build(), the token credential is assigned to the Service Bus options only if the connection string has no SAS token/key. The Service Bus connection then uses the issued AAD bearer token in place of a shared key.
Domain Language
See the module domain glossary: ../CONTEXT.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Azure.Identity (>= 1.21.0)
- Chatter.MessageBrokers.AzureServiceBus (>= 2.1.0)
-
net8.0
- Azure.Identity (>= 1.21.0)
- Chatter.MessageBrokers.AzureServiceBus (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1 | 577 | 9/24/2026 |
| 4.0.0 | 114 | 9/24/2026 |
| 3.2.1 | 140 | 9/2/2026 |
| 3.2.0 | 132 | 9/1/2026 |
| 3.1.2 | 126 | 9/1/2026 |
| 3.1.1 | 131 | 8/26/2026 |
| 3.1.0 | 135 | 8/25/2026 |
| 3.0.0 | 696 | 6/16/2026 |
| 2.0.0 | 148 | 5/30/2026 |
| 1.3.0 | 7,686 | 12/10/2021 |
| 1.2.0 | 779 | 11/11/2021 |
| 1.1.0 | 801 | 5/29/2021 |
| 1.0.2 | 1,717 | 1/30/2021 |
| 1.0.1 | 698 | 1/29/2021 |
| 1.0.0 | 751 | 1/17/2021 |