How to make Keycloak automatically redirect to login page if request fails

3.9k Views Asked by At

I have an Keycloak server and using mod_auth on Apache to manage the request.

Currently, in my client application, when I face with a 401 request, I trigger an location.reload() and thus being redirected to Keycloak logging page. But this feel very unnatural.

I want to ask if there is another, office way that do the redirecting automatically from Keycloak side/server side?

//////Edited////

I use mod_auth_openidc for Apache, which mean there is no adapter on client-side

Keyckoak version:4.4.0

1

There are 1 best solutions below

0
On

You can use OIDCUnAuthAction to configure the action to be taken on an incoming unauthenticated request, see: https://github.com/zmartzone/mod_auth_openidc/blob/v2.3.8/auth_openidc.conf#L697

This is a per-path/location/directory setting, so in your case you'd configure:

OIDCUnAuthAction auth

on that specific path.