I have the following setup for my application:
- A User logs in and is granted a Session Token.
- When making API requests to Service A the User provides the Session Token.
- All requests go through an API Gateway which internally re-directs the request to an Authorization Service which authenticates the Session Token and generates a JWT with appropriate authorization information for all services.
- The API Gateway redirects the request back to Service A with the newly generated JWT.
- Service A validates and then uses the JWT for authorization (i.e. this user has permission to perform this action given the information in this JWT).
- Service A can pass that same JWT to any downstream services it needs to make requests to. Those services treat authorization/authentication in the same way without having to go back to the Authorization Service.
This works well for requests generated by a user.
The trouble I'm having is extending this general setup to "asynchronous" requests, where Service A may need to make a request to Service B sometime in the future, or completely separate from a User request. The problem being, how does Service A itself generate a JWT to pass to Service B? Obviously the service cannot "log-in" the same way a User can to get a Session Token to provide to the Authorization Service to generate a JWT for it, similar to the way it worked for a User request.
What I don't want to do is share the same secret between all services so that they can generate their own valid JWT. I would like that centralized to some authority which the services can register themselves against.
One objection would be, why does Service A need to be authorized to make the request to Service B? They are all in the same intra-network so they can be trusted via other means. The answer is that I don't want to set up a separate API for intra-network requests versus public facing APIs, for every micro-service, for every endpoint. So if both Users and Services are to use the same endpoints, they both will need to provide a valid JWT to be authorized. Now, the JWT body doesn't have to look the same for both users and services, but it does have to be passed and be validated by whatever service is receiving it.
I'm not necessarily looking for a solution, any resources or standard patterns for achieving this type of authorization would be immensely helpful.