@@ -143,6 +143,16 @@ public class EventHubTarget : AsyncTaskTarget
143143 /// </summary>
144144 public Layout AccessKey { get ; set ; }
145145
146+ /// <summary>
147+ /// clientId for <see cref="Azure.Identity.ClientSecretCredential"/> authentication. Requires <see cref="ServiceUri"/>, <see cref="TenantIdentity"/> and <see cref="ClientAuthSecret"/>.
148+ /// </summary>
149+ public Layout ClientAuthId { get ; set ; }
150+
151+ /// <summary>
152+ /// clientSecret for <see cref="Azure.Identity.ClientSecretCredential"/> authentication. Requires <see cref="ServiceUri"/>, <see cref="TenantIdentity"/> and <see cref="ClientAuthId"/>.
153+ /// </summary>
154+ public Layout ClientAuthSecret { get ; set ; }
155+
146156 /// <summary>
147157 /// The connection uses the AMQP protocol over web sockets. See also <see cref="EventHubsTransportType.AmqpWebSockets"/>
148158 /// </summary>
@@ -209,6 +219,8 @@ protected override void InitializeTarget()
209219 string sharedAccessSignature = string . Empty ;
210220 string storageAccountName = string . Empty ;
211221 string storageAccountAccessKey = string . Empty ;
222+ string clientAuthId = string . Empty ;
223+ string clientAuthSecret = string . Empty ;
212224 string eventHubName = string . Empty ;
213225 string useWebSockets = string . Empty ;
214226 string webSocketProxyAddress = string . Empty ;
@@ -229,6 +241,8 @@ protected override void InitializeTarget()
229241 sharedAccessSignature = SharedAccessSignature ? . Render ( defaultLogEvent ) ;
230242 storageAccountName = AccountName ? . Render ( defaultLogEvent ) ;
231243 storageAccountAccessKey = AccessKey ? . Render ( defaultLogEvent ) ;
244+ clientAuthId = ClientAuthId ? . Render ( defaultLogEvent ) ;
245+ clientAuthSecret = ClientAuthSecret ? . Render ( defaultLogEvent ) ;
232246 }
233247
234248 useWebSockets = UseWebSockets ? . Render ( defaultLogEvent ) ?? string . Empty ;
@@ -239,7 +253,7 @@ protected override void InitializeTarget()
239253 customEndPointAddress = CustomEndpointAddress ? . Render ( defaultLogEvent ) ?? string . Empty ;
240254 webSocketProxyAddress = WebSocketProxyAddress ? . Render ( defaultLogEvent ) ?? string . Empty ;
241255
242- _eventHubService . Connect ( connectionString , eventHubName , serviceUri , tenantIdentity , managedIdentityResourceId , managedIdentityClientId , sharedAccessSignature , storageAccountName , storageAccountAccessKey , bool . TrueString == useWebSockets , webSocketProxyAddress , customEndPointAddress ) ;
256+ _eventHubService . Connect ( connectionString , eventHubName , serviceUri , tenantIdentity , managedIdentityResourceId , managedIdentityClientId , sharedAccessSignature , storageAccountName , storageAccountAccessKey , clientAuthId , clientAuthSecret , bool . TrueString == useWebSockets , webSocketProxyAddress , customEndPointAddress ) ;
243257 InternalLogger . Debug ( "AzureEventHubTarget(Name={0}): Initialized" , Name ) ;
244258 }
245259 catch ( Exception ex )
@@ -542,7 +556,7 @@ private sealed class EventHubService : IEventHubService
542556
543557 public string EventHubName { get ; private set ; }
544558
545- public void Connect ( string connectionString , string eventHubName , string serviceUri , string tenantIdentity , string managedIdentityResourceId , string managedIdentityClientId , string sharedAccessSignature , string storageAccountName , string storageAccountAccessKey , bool useWebSockets , string webSocketsProxyAddress , string endPointAddress )
559+ public void Connect ( string connectionString , string eventHubName , string serviceUri , string tenantIdentity , string managedIdentityResourceId , string managedIdentityClientId , string sharedAccessSignature , string storageAccountName , string storageAccountAccessKey , string clientAuthId , string clientAuthSecret , bool useWebSockets , string webSocketsProxyAddress , string endPointAddress )
546560 {
547561 EventHubName = eventHubName ;
548562
@@ -574,6 +588,11 @@ public void Connect(string connectionString, string eventHubName, string service
574588 {
575589 _client = new Azure . Messaging . EventHubs . Producer . EventHubProducerClient ( serviceUri , eventHubName , new Azure . AzureNamedKeyCredential ( storageAccountName , storageAccountAccessKey ) , options ) ;
576590 }
591+ else if ( ! string . IsNullOrEmpty ( clientAuthId ) && ! string . IsNullOrEmpty ( clientAuthSecret ) && ! string . IsNullOrEmpty ( tenantIdentity ) )
592+ {
593+ var tokenCredentials = new Azure . Identity . ClientSecretCredential ( tenantIdentity , clientAuthId , clientAuthSecret ) ;
594+ _client = new Azure . Messaging . EventHubs . Producer . EventHubProducerClient ( serviceUri , eventHubName , tokenCredentials ) ;
595+ }
577596 else
578597 {
579598 var tokenCredentials = AzureCredentialHelpers . CreateTokenCredentials ( managedIdentityClientId , tenantIdentity , managedIdentityResourceId ) ;
0 commit comments