Hi,
I'm building several micro services with following architecture using lagom with Maven.
- Micro service 1: auth-api and auth-api-impl - which handles the authentication for all service calls coming to all services
- Micro service 2: api-1 and api-1-impl - A generic micro service
- Micro service 2: api-2 and api-2-impl - Another generic micro service
I'm using JWT based authentication in auth-api. auth-api has two API calls (Class AuthService).
ServiceCall<AuthRequest, AuthResponse> login(); //returns a jwt token
ServiceCall<RequestHeader, NotUsed> auth(); //analyzes the request header and validates the jwt token
All the other APIs are called from outside and the caller will add the JWT token to the header. So all the api calls which coming to api-1 and api-2 should go through auth() api call and authenticate first.
I wrote a HeaderFilter for this purpose as
this documentation says. The custom HeaderFilter is placed in the
auth-api. Now api-1 and api-2 can use that header filter, so all the API-calls will route through that HeaderFilter. Now i'm trying to trigger auth() api call from inside the HeaderFilter. That is where I fail. I tried using
@Inject too. But it does not work. Authservice object is always null.
@Inject
private AuthService authService;
@Override
public RequestHeader transformClientRequest(RequestHeader request) {
authService.auth().invoke(request);
return request;
}
Then I moved HeaderFilter from auth-api to api-1 and used bindClient method as
this doc says. Still the result is same.
@Override
protected void configure() {
bindClient(AuthService.class);
}
Am I missing anything here? Can't we utilize other micro services from HeaderFilters?