Skip to content

#13166 loginPersistence option and server logout on a failed token refresh - #13171

Open
afabiani wants to merge 2 commits into
masterfrom
master-login-browser-session
Open

afabiani wants to merge 2 commits into
masterfrom
master-login-browser-session

Conversation

@afabiani

@afabiani afabiani commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Description

A login with OpenID Connect survives a browser restart, because the security state, access token included, is kept in localStorage. The next token refresh then renews the session for as long as the session at the identity provider is valid. And when a token refresh fails, MapStore only clears its own state: DELETE /session/logout is sent only by the Logout button, so the session on the server and at the identity provider stays alive.

  • New localConfig.json option loginPersistence: local (the default, as today) or browserSession. With browserSession, a session cookie (ms2-login-session, on the path of the application) marks the browser session at login and is removed at logout. A persisted login without it is not restored: MapStore starts logged out and sends DELETE /session/logout with the stored access token. This covers a login left by an earlier browser session and one made before the option was turned on. The login is still shared by the tabs of the browser and survives page reloads.
  • When a token refresh fails, MapStore logs out locally as before and also sends DELETE /session/logout with the token it held.
  • In both cases MapStore dispatches a new action, SESSION_ENDED, with reason set to browserSession or refreshFailed (SESSION_END_REASONS), so that a project can react to it, for example with a notice. The first is dispatched on the first location change, once the application has started; the Logout button does not dispatch it.

With globalLogoutEnabled, GeoStore then also ends the session at the identity provider. When the stored access token has already expired, that needs geosolutions-it/geostore#611 and geosolutions-it/geostore#613 (GeoStore 2.7.1); older versions just answer the logout without effect at the provider.

Please check if the PR fulfills these requirements

Issue

What is the current behavior?
#13166

After a browser restart MapStore still shows the user as logged in and the next refresh renews the session. After a failed refresh the session on the server and at the identity provider stays alive.

What is the new behavior?
With loginPersistence: "browserSession", a browser restart ends the login, in MapStore and on the server. With any setting, a failed refresh ends the session on the server too. In both cases MapStore dispatches SESSION_ENDED with the reason.

Other useful information

Unit tests: LoginPersistenceUtils-test, new cases in StandardStore-test (restored with the marker and by default, dropped and logged out on the server without it), security-test (a failed refresh dispatches LOGOUT and SESSION_ENDED and sends the logout with the old token, a successful one does not) and login-test (the marker is set at login and removed at logout only with browserSession; SESSION_ENDED is dispatched once after a login was dropped at startup). The whole suite passes locally.

I also tested it in Chromium with Playwright, against Keycloak 26.0.7 (access tokens of 60 seconds) and a GeoStore build with #611 and #613, globalLogoutEnabled=true. The number of sessions of the user in Keycloak was read through its admin API after each step. A browser restart was simulated by dropping the session cookies and keeping localStorage and the persistent cookies. The actions were recorded in debug mode (?debug=true) through a stand-in for the Redux devtools hook.

Case Result
browserSession, page reload still logged in, no logout sent
browserSession, restart after the access token expired logged out, DELETE /session/logout with the stored token (204), Keycloak sessions 1 → 0
browserSession, restart with the token still valid the same, without any refresh attempt first
browserSession, restart SESSION_ENDED with browserSession and no LOGOUT at startup
browserSession, Logout button DELETE /session/logout (204), marker removed, Keycloak sessions 1 → 0; LOGOUT only, no SESSION_ENDED
login made with the default, then browserSession turned on ended at the next page load, Keycloak sessions 1 → 0
default, restart with the token still valid still logged in, as before
default, restart after the access token expired refresh refused (403), logged out, DELETE /session/logout (204), Keycloak sessions 1 → 0, LOGOUT then SESSION_ENDED with refreshFailed; without this change the same case left the Keycloak session alive (1)

Browsers set to restore the previous session at startup also restore session cookies, so with them the login is kept; the documentation says so.

…fresh

A new localConfig.json option, loginPersistence, set to browserSession ties
the login to the browser session. A session cookie marks the browser session
at login; a persisted login without it, left by an earlier browser session or
made before the option was turned on, is not restored, and its session is
ended on the server with its own access token.

When a token refresh fails, MapStore now also sends the logout to the server
with the token it held, instead of clearing only the client state.
A new action, SESSION_ENDED, carries the reason when MapStore ends a login
without a user action: browserSession when a stored login of an earlier
browser session is not restored, refreshFailed when the token refresh fails.
The first is dispatched on the first location change, once the application
has started. The Logout button does not dispatch it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenID Connect login survives a browser restart: option to tie the login to the browser session

1 participant