Skip to main content

Discovery Proxy

The problemโ€‹

HAPI FHIR JPA does not serve /.well-known/smart-configuration natively. SMART clients send discovery requests to the FHIR base URL (iss), so without this filter they get a 404.

SmartDiscoveryProxyFilterโ€‹

SmartDiscoveryProxyFilter is an OncePerRequestFilter that intercepts GET /fhir/.well-known/smart-configuration on the HAPI server and forwards it to the Auth Server:

@Override
protected void doFilterInternal(HttpServletRequest req,
HttpServletResponse res,
FilterChain chain) {
String targetUrl = authServerUrl + "/.well-known/smart-configuration";
HttpResponse<String> proxyResponse = httpClient.send(
HttpRequest.newBuilder(URI.create(targetUrl)).GET().build(),
HttpResponse.BodyHandlers.ofString()
);
res.setContentType("application/json");
res.getWriter().write(proxyResponse.body());
}

Registering on HAPIโ€‹

Option A โ€” Spring filter registration:

@Bean
public FilterRegistrationBean<SmartDiscoveryProxyFilter> discoveryProxy() {
FilterRegistrationBean<SmartDiscoveryProxyFilter> reg =
new FilterRegistrationBean<>();
reg.setFilter(new SmartDiscoveryProxyFilter("http://localhost:9000"));
reg.addUrlPatterns("/.well-known/*");
reg.setOrder(1);
return reg;
}

Option B โ€” nginx reverse proxy:

location /.well-known/smart-configuration {
proxy_pass http://localhost:9000/.well-known/smart-configuration;
}

Testingโ€‹

# Should return the same JSON as:
curl http://localhost:8080/fhir/.well-known/smart-configuration
curl http://localhost:9000/.well-known/smart-configuration