rebus-org / Rebus.AzureServiceBus

:bus: Azure Service Bus transport for Rebus
https://mookid.dk/category/rebus
Other
33 stars 20 forks source link

Allow token-based authentication (Issue #50) #51

Closed eeskildsen closed 4 years ago

eeskildsen commented 4 years ago

This change lets a consumer pass an ITokenProvider to Rebus. The token provider is then passed to the underlying Azure Service Bus clients.

Token providers support authentication methods beyond SAS. For example, they support Azure Active Directory, which can be used for Role-Based Access Control (RBAC). This gives the consumer more granular access control over queues and topics.

I implemented this as an optional parameter in UseAzureServiceBus. The argument (default null) is passed to the transport constructor. If the argument is null, the various Service Bus clients are instantiated with the same constructor overloads that were in the code before my changes. If the parameter is not null, alternative constructor overloads, which accept ITokenProviders, are called instead.

I added a passing test in TokenProviderTest, but it only covers queues.

Let me know if any questions, suggestions, etc....


Rebus is MIT-licensed. The code submitted in this pull request needs to carry the MIT license too. By leaving this text in, I hereby acknowledge that the code submitted in the pull request has the MIT license and can be merged with the Rebus codebase.

claassistantio commented 4 years ago

CLA assistant check
All committers have signed the CLA.

mookid8000 commented 4 years ago

I'm happy with how simple and straightforward this addition looks! πŸ™‚

mookid8000 commented 4 years ago

Cool.... would now be a good time to merge your PR? πŸ˜„

eeskildsen commented 4 years ago

Cool.... would now be a good time to merge your PR? πŸ˜„

Yep, it should be good to go!

mookid8000 commented 4 years ago

Excellent! Your contribution is out in Rebus.AzureServiceBus 7.1.0, which is on NuGet.org as soon as they update their index πŸ™‚

Thanks for your contribution! πŸ‘

asleire commented 4 years ago

The added parameter to UseAzureServiceBus causes an incompatability between 7.0.0 and 7.1.0 which could've been avoided as described here https://stackoverflow.com/questions/44104352/adding-option-parameter-to-a-library-in-c-sharp-without-creating-a-breaking-chan

Something to watch out for in the future πŸ™‚