You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Azure Event Hubs supports using Azure Active Directory (Azure AD) to authorize requests to Event Hubs resources. With Azure AD, you can use Azure role-based access control (Azure RBAC) to grant permissions to a security principal, which may be a user, or an application service principal.
47
+
48
+
If you want to run this sample locally with Azure AD authentication, be sure your user account has authenticated via Azure Toolkit for IntelliJ, Visual Studio Code Azure Account plugin, or Azure CLI. Also, be sure the account has been granted sufficient permissions.
49
+
50
+
> [!NOTE]
51
+
> You need to set the following data plane access roles: `Azure Event Hubs Data Sender` and `Azure Event Hubs Data Receiver`.
52
+
53
+
To authenticate using the Azure CLI, use the following steps.
54
+
55
+
1. First, use the following command to get the resource ID for your Azure Event Hubs namespace:
56
+
57
+
```azurecli
58
+
export AZURE_RESOURCE_ID=$(az resource show \
59
+
--resource-group $AZ_RESOURCE_GROUP \
60
+
--name $AZ_EVENTHUBS_NAMESPACE_NAME \
61
+
--resource-type Microsoft.EventHub/Namespaces \
62
+
--query "id" \
63
+
--output tsv)
64
+
```
65
+
66
+
1. Second, use the following command to get your user object ID of your Azure CLI user account:
67
+
68
+
```azurecli
69
+
export AZURE_ACCOUNT_ID=$(az ad signed-in-user show \
70
+
--query "id" --output tsv)
71
+
```
72
+
73
+
1. Then, use the following commands to assign the `Azure Event Hubs Data Sender` and `Azure Event Hubs Data Receiver` roles to your account.
74
+
75
+
```azurecli
76
+
az role assignment create \
77
+
--assignee $AZURE_ACCOUNT_ID \
78
+
--role "Azure Event Hubs Data Receiver" \
79
+
--scope $AZURE_RESOURCE_ID
80
+
81
+
az role assignment create \
82
+
--assignee $AZURE_ACCOUNT_ID \
83
+
--role "Azure Event Hubs Data Sender" \
84
+
--scope $AZURE_RESOURCE_ID
85
+
```
86
+
87
+
For more information about granting access roles, see [Authorize access to Event Hubs resources using Azure Active Directory](/azure/event-hubs/authorize-access-azure-active-directory).
88
+
89
+
Once your user account is authenticated, you can update use following configuration in `src/main/resources/producer.config` as shown below.
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/producer/src/main/java).
> Replace `{YOUR.EVENTHUBS.CONNECTION.STRING}` with the connection string for your Event Hubs namespace. For instructions on getting the connection string, see [Get an Event Hubs connection string](event-hubs-get-connection-string.md). Here's an example configuration: `sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXX";`
52
114
53
-
**OAuth:**
115
+
> [!IMPORTANT]
116
+
> Replace `{YOUR.EVENTHUBS.CONNECTION.STRING}` with the connection string for your Event Hubs namespace. For instructions on getting the connection string, see [Get an Event Hubs connection string](event-hubs-get-connection-string.md). Here's an example configuration: `sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXX";`
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/producer/src/main/java).
122
+
64
123
4. Run the producer code and stream events into Event Hubs:
65
124
66
125
```shell
@@ -72,31 +131,46 @@ When you create an Event Hubs namespace, the Kafka endpoint for the namespace is
72
131
73
132
6. Update the configuration details forthe consumerin`src/main/resources/consumer.config` as follows:
> Replace `{YOUR.EVENTHUBS.CONNECTION.STRING}` with the connection string for your Event Hubs namespace. For instructions on getting the connection string, see [Get an Event Hubs connection string](event-hubs-get-connection-string.md). Here's an example configuration: `sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXX";`
137
+
Make sure you configure Azure AD authentication as mentioned in step 3 and use the followning consumer configuration.
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/consumer/src/main/java).
149
+
150
+
You can find all the OAuth samples for Event Hubs for Kafka [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth).
> Replace `{YOUR.EVENTHUBS.CONNECTION.STRING}` with the connection string for your Event Hubs namespace. For instructions on getting the connection string, see [Get an Event Hubs connection string](event-hubs-get-connection-string.md). Here's an example configuration: `sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXX";`
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/consumer/src/main/java).
98
173
99
-
You can find all the OAuth samples for Event Hubs for Kafka [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth).
100
174
7. Run the consumer code and process events from event hub using your Kafka clients:
0 commit comments