I'm using JHipster gateway with Keycloak as identity provider.
Sometimes an error occurs during the Keycloak login process. Keycloak then routes me back to the gateway with this path: https://my-gateway-url/login?error.
The gateway doesn't show a login error page, but instead shows the following:
{
"type": "https://www.jhipster.tech/problem/problem-with-message",
"title": "Unauthorized",
"status": 401,
"detail": "Not Authenticated",
"path": "/login",
"message": "error.http.401"
}
Is there a way to let the gateway show a custom error page when keycloak redirects to /login?error
, or if not, possibly a simple way to change the redirect logic in Keycloak so that it doesn't redirect to /login?error
?
I'm not so clued up with how /login is handled within the gateway.
I have tried to play around with SpaWebFilter.java to force a redirect to /error/login where I have a custom error page, but it did not work and gave the same error as previous.
public class SpaWebFilter implements WebFilter {
/**
* Forwards any unmapped paths (except those containing a period) to the client {@code index.html}.
*/
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
String path = exchange.getRequest().getURI().getPath();
String query = exchange.getRequest().getURI().getQuery();
if (
!path.startsWith("/api") &&
!path.startsWith("/management") &&
!path.startsWith("/login") &&
!path.startsWith("/services") &&
!path.startsWith("/v3/api-docs") &&
path.matches("[^\\\\.]*")
) {
return chain.filter(exchange.mutate().request(exchange.getRequest().mutate().path("/index.html").build()).build());
} else if(path.startsWith("/login") && query != null && query.equals("error")) {
return chain.filter(exchange.mutate().request(exchange.getRequest().mutate().path("/error/login").build()).build());
}
return chain.filter(exchange);
}
}