title: How do I associate Authorization data throughout an entire "transaction" in MassTransit?
body: <p>I've only been using MassTransit (and SOA) for about 2 weeks now and I like it so far but I'm struggling getting a few concepts to transfer over mentally and maybe I'm just thinking about it completely the wrong way. My company has a legacy application that uses a one tenent per database strategy that I can't change. I've figured out how to get NHibernate to handle that using a tenent key, more less. Anytime I want to access the database, I must supply this tenent key to get the correct session factory (from the IoC container).</p>
  
  <p>We're beginning with a more "traditional" approach just to get our data access and business logic into the service providing the MassTransit connection by using the Request-Reply pattern with our WebAPI project. This project uses OAuth2 for authentication and as a result the users identity is available in the User property of the controller where we also store the tenent key.</p>
  
  <p>My first thought was to just set the CurrentPrincipal on the thread to the ClaimsPrincipal in the User property but that only does it for the WebRequest thread. Then I realized that each Consumer/Activity I created would probably be in their own threads also. It was easy enough to add the bare minimum data to the header of the RequestClient so that the first Consumer would have it and create middleware to automatically retrieve it and recreate the ClaimsPrincipal (was not serialized though becuase that's not possible). But if that Consumer creates a RoutingSlip, the header is not passed to it and so none of the Activities would be able to use a similar middleware.</p>
  
  <p>Optimally, I'd like my authorization data to be associated to all messages in the chain until the Reply is given but I can't seem to find any examples of what I'm trying to do anywhere, which is why I think I may be thinking about this incorrectly. Short of that, being able to use IoC for all the related messages would be cool too. I'd rather not have to make the authroization data part of the message data for the Consumer/Activities because that would create more points of failure.</p>
  
  <p>Can anyone point me in the right direction for doing this?</p>