You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This middleware is used by all microservices. When the microservice is the auth service, it essentially invokes itself. When the microservice is not the auth service, it makes a remote call to the auth service.
Is this a good approach, or should I change the logic within the middleware so that the auth service avoids making a remote call to itself? Alternatively, should I use two different middlewares?
The AuthenticateMiddleware always uses RemoteServiceClient to verify tokens via HTTP call:
When running in the auth service, this creates a self-call (HTTP roundtrip to itself) - wasteful and adds latency
When running in cms/dam services, this is the correct behavior (calling auth service remotely)
Recommendation: Use a Token Verification Abstraction
I recommend neither two separate middlewares nor conditional logic in the middleware. Instead, use Dependency Injection properly by creating a TokenVerifier abstraction that has two implementations: