-
I have an application as a monolith that exposes a REST API and uses AuthN/AuthZ, where the request may come with one or two JWT tokens as headers:
The first token is an OAuth2
We need such representation later when calling an external API to set it as parameters to an external URL. due to the way that this external API works (it requires setting the security params as part of the URL itself). Because this is now a monolith, it was easier for us to construct such representation in the MVC layer, then propagate it across all the layers (cluttering lots of services' methods with concerns that they are not actually interested in, though) into the final invocation of the external URL. Now I would like to move all this to a hexagonal architecture, but I'm struggling with this specific concern, as based on my understanding:
So applying a hexagonal architecture and avoiding coupling between layers or managing concerns in layers where I shouldn't, my initial solution could be:
Therefore, the following questions pop up:
I'm a bit confused here, so any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's hard to tell without implementing it in code and experimenting a little bit.
Application services in the application core are just a bridge that orchestrates different parts of your applications, so IMO it's fine to do it in application services if you need to. But you could avoid that and just get the Here is some example code in typescript: // Middleware that is executed before your request reaches your handlers
use(req: Request, res: Response, next: NextFunction) {
const requestType = convertHeadersToRequestType(req.headers);
requestContext.set('requestTypes', requestTypes);
next();
} // Adapter that calls external API
const requestType = requestContext.get('requestTypes');
// ... call external api with this request type I guess in Java you could use |
Beta Was this translation helpful? Give feedback.
It's hard to tell without implementing it in code and experimenting a little bit.
If you need to get this tokens for every endpoint, the simplest solution that comes to mind is to use some kind of middleware that intercepts your HTTP request and extracts the token, converts it to the
RequestType
then sets it somewhere in a request context. When you need to call an external API with thatRequestType
you just get it from the context. This way you avoid propagating it everywhere.Application services in the application core are just a b…