Updated Service Bus 1.1 for Windows Server 1.0.4 Client Assembly

The Service Bus team has released an updated client assembly on nuget for Service Bus for Windows Server 1.1.  This update addresses a SAS feature that was added to the Azure Service Bus client in the 2.4 release: the ability to create a connection to Service Bus using only a token and not SAS Key. 

 

This enables scenarios where clients can be granted a SAS token and not be given the more sensitive SAS key.  This enables a much easier SAS authentication experience for our on premises product. 

 

The added method to the TokenProvider class is highlighted below.  To use this technique simply create a SAS token from the SAS key, as shown in the Main() method, then use the token in CreateSharedAccessSignatureTokenProvider(string) to create the token provider like you normally would.  Pass this token provider to the MessagingFactory and you have SAS token based authentication. 

 

 

static void Main()

{

  conststring sharedAccessKeyName = "all";

  conststring sharedAccessKey = "<my key>";

   var sasTokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sharedAccessKeyName, sharedAccessKey);

   var token = sasTokenProvider.GetWebTokenAsync(serviceBusNamespace + "/" + queueName, "NotUsedWithSAS", false, TimeSpan.FromSeconds(15)).Result;

  ChildOperation(token);

}

 

static void ChildOperation(string token)

{

   var existingTokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(token);

   var messagingFactory = MessagingFactory.Create("sb://" + serviceBusNamespace, existingTokenProvider);

   var queueClient = messagingFactory.CreateQueueClient(queueName);

  queueClient.Send(newBrokeredMessage("test"));

  Console.WriteLine("Successfully sent message to {0}!", queueClient.Path);

  var m = queueClient.Receive();

  Console.WriteLine("Received '{0}' from {1}!", m, queueClient.Path);

  var namespaceManager = newNamespaceManager("https://" + serviceBusNamespace, existingTokenProvider);

  var queueDescription = namespaceManager.GetQueue(queueName);

  Console.WriteLine("Got QueueDescription for '{0}': MessageCount: {1}", queueDescription.Path, queueDescription.MessageCount);

}

 

As we have made SAS the default authentication provider for Azure Service Bus we want to continue to keep our Service Bus for Windows Server experience as consistent as possible.  A big thank you to one of our awesome devs for enabling this scenario!