Skip to content

Commit e77f49c

Browse files
committed
Feedback from the Service Bus product team
1 parent 842e4b6 commit e77f49c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

articles/service-bus-messaging/service-bus-managed-service-identity.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@ Here are the high-level steps to use a managed identity to access a Service Bus
1414
- [Configure managed identities for App Service and Azure Functions](../app-service/overview-managed-identity.md)
1515
- [Configure managed identities for Azure resources on a VM](../active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm.md)
1616
1. Assign Azure Service Bus Data Owner, Azure Service Bus Data Sender, or Azure Service Bus Data Receiver role to the managed identity at the appropriate scope (Azure subscription, resource group, Service Bus namespace, or Service Bus queue or topic). For instructions to assign a role to a managed identity, see [Assign Azure roles using the Azure portal](../role-based-access-control/role-assignments-portal.yml).
17-
1. In your application, use the managed identity and the endpoint to Service Bus namespace to connect to the namespace. For example, in .NET, you use the [ServiceBusClient](/dotnet/api/azure.messaging.servicebus.servicebusclient.-ctor#azure-messaging-servicebus-servicebusclient-ctor(system-string-azure-core-tokencredential)) constructor that takes `TokenCredential` and `fullyQualifiedNamespace` (a string, for example: `cotosons.servicebus.windows.net`) parameters to connect to Service Bus using the managed identity. You pass in [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential), which derives from `TokenCredential` and uses the managed identity.
17+
1. In your application, use the managed identity and the endpoint to Service Bus namespace to connect to the namespace.
18+
19+
For example, in .NET, you use the [ServiceBusClient](/dotnet/api/azure.messaging.servicebus.servicebusclient.-ctor#azure-messaging-servicebus-servicebusclient-ctor(system-string-azure-core-tokencredential)) constructor that takes `TokenCredential` and `fullyQualifiedNamespace` (a string, for example: `cotosons.servicebus.windows.net`) parameters to connect to Service Bus using the managed identity. You pass in [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential), which derives from `TokenCredential` and uses the managed identity. In `DefaultAzureCredentialOptions`, set the `ManagedIdentityClientId` to the ID of client's managed identity.
20+
21+
```csharp
22+
string fullyQualifiedNamespace = "<your Namespace>.servicebus.windows.net>";
23+
string userAssignedClientId = "<your managed identity client ID>";
24+
25+
var credential = new DefaultAzureCredential(
26+
new DefaultAzureCredentialOptions
27+
{
28+
ManagedIdentityClientId = userAssignedClientId
29+
});
30+
31+
var sbusClient = new ServiceBusClient(fullyQualifiedNamespace, credential);
32+
```
1833

1934
> [!IMPORTANT]
2035
> You can disable local or SAS key authentication for a Service Bus namespace and allow only Microsoft Entra authentication. For step-by-step instructions, see [Disable local authentication](disable-local-authentication.md).

0 commit comments

Comments
 (0)