Search code examples
vaadinvaadin-flowvaadin10vaadin14

how to handle SSO redirect in Vaadin 14


We have a Vaadin 14 (Flow) application which is fronted by an Apache reverse proxy that integrates with Gluu for authentication.

When the session is not valid anymore, either because of session timeout or a logout in another browser tab/window, the Apache server will send a redirect to the Gluu server to let the user log in again. However when this happens for an internal Vaadin XHR call (Ajax request), Vaadin does not seem to handle this response very well, and shows an "Invalid JSON response from server" error.

What I want is either for Vaadin to set the browser location to the URL indicated in the redirect, or refresh the page (maybe with a confirmation message between) in which case the browser will nicely follow the redirect. How can this be achieved, or what other options are there?


Solution

  • If the XHR response cannot be parsed as JSON, Vaadin will look for a Vaadin-Refresh string anywhere inside the response text. If it's present, then Vaadin will reload the page instead of showing an error message. Optionally, you can use the format Vaadin-Refresh: <url> which will make Vaadin redirect to <url> rather than reloading the current location.

    You can configure Gluu to include this string as e.g. a HTML comment in the response that is sent when the user needs to log in.