Send current Principal with MassTransit

187 Views Asked by At

When cosuming message I need to know Principal who sent it. Cannot find any more or less standard way of sending Principal via MassTransit. Found one similar question but this not exact what I want. Can you please share some thoughts or code examples.

1

There are 1 best solutions below

0
Alexey Zimarev On

I still would promote proper separation of concerns. The application service has no interest in tokens, claims and subs. It needs to know who the user is and what they have, so it can perform authorisation tasks (which are not authentication tasks).

Therefore, it doesn't matter, how the user information is conveyed to the API. Strong coupling between the identity management infrastructure and application services do more hard than good and produce these issues.

If we take the plain HTTP API, it would work like this:

WebAPI flow

When moving to messaging, the user identity becomes part of the message. We could argue if it should be in the message header, however, I personally consider it important business data and put it to the message contract itself.

Here how I would do it with messaging between HTTP API and the app service:

enter image description here