Skip to content

check-sso waits for the login-status iframe before silent SSO, which always runs for logged-in users #375

Open

Description

@dpkass

Line numbers refer to lib/keycloak.js at be42d6a (26.2.5).

Description

With onLoad: 'check-sso' and the login iframe enabled, init() first sets up login-status-iframe.html (one page load plus its /init request), waits for its first answer, and only then starts silent SSO (lines 921–928).

On a fresh page load there is no token yet, so the iframe is asked about an empty session ID (line 1040). For a user who has a Keycloak session, it answers changed, and silent SSO runs anyway. We confirmed this by logging the message events on reload: supported (cookie check), changed (login iframe), then the silent SSO callback.

So for logged-in users, the first iframe check adds two serial round trips and can never skip anything. It only saves the silent SSO request for users without a session. In our measurements that's ~250 ms per app start at ~120 ms per round trip.

Proposed change

For check-sso without stored tokens, run silent SSO (or doLogin(false)) directly. Set up the login iframe after authentication, or in parallel, so it can still monitor the session afterwards.

For logged-out users, silent SSO's login_required response replaces the iframe's unchanged answer at about the same cost. For logged-in users, startup gets two round trips shorter. Session monitoring is kept either way.

Measurements

Our app, warm-session reloads, medians of 7, 120 ms of added latency per request (the app's own minimum loading-screen time disabled so only Keycloak differs):

Configuration Keycloak init() round trips Home page visible
Default (cookie check, login iframe, silent SSO) 6 1,401 ms
checkLoginIframe: false 4 1,153 ms
Login iframe off and cookie check skipped 2 889 ms

Happy to open a PR.

Drafted with AI assistance; the analysis and measurements are from our app.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions