Customize keycloak error page with spring boot

I use keycloak-spring-boot-starter to protect my rest-service from unauthorized access. The authentication works as expected, but if the authentication fails, then it returns an empty response.

However, I’d like to return a json error response similar to all my other error handlers. I already tried to define an @ExceptionHandler(Throwable.class), ErrorController, ErrorViewResolver or configuring the ErrorPages via WebServerCustomizer, but that doesn’t work at all.

I’m totally fine, if I could define a static response for it.

There seems to be a property called delegateBearerErrorResponseSending, but I couldn’t find where to set it. It isn’t present in spring-boot’s properties. I’m not even sure where the call will be delegated to.

There is a property called policy-enforcer-config.on-deny-redirect-to, but a redirect isn’t the expected behavior for a rest service.

  • spring-boot: 2.3.1.RELEASE
  • keycloak-spring-boot-starter: 10.0.2

TLDR: How do I configure/customize the error page for keycloak.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.