I am confused - what is best way to pass user identity (authorization information) between microservices in asynchronous way?
Lets say I already have entry point (api gateway) that handes authentication and issues JWT tokens. Then user calls some API endpoint with this token. Up to this point everything is clear. Now - this endpoint needs to communicate with another microservice. That microservice must get authorization information (roles, etc). Also - this channel is asynchronous (JMS/Kafka), which means processing might be dalayed...
I was also thinking about other case: we have two services A and B. both expose API that might be accessed by external user (JWT token auth), but they also need to cooperate asynchronously (by JMS). They both need user identity context. Again - how to pass it?
I can:
- pass JWT token along with queue message - is it safe? what if tokens expires before target service starts processing?
- convert information from JWT token and pass it as HTTP headers - what if target service returns information - I need to regain authorization context from that response (it must be still processed in context of specific user), but this makes me handle two types of authorization: JWT and the one returned from asynch process...
- ...?
all of them have cons for me and I cannot find universal solution...
--Edit
Consider case: there is product catalog service and ordering service. Both expose public API. User places order, it is queued for processing. First step is to verify if products are ok and user was allowed to order them. Processing may call product catalog service but has to pass user context. This is the part that I am talking about.