✨ Prefill Keycloak login and registration fields from voting links - #2907
Open
edulix wants to merge 13 commits into
Open
✨ Prefill Keycloak login and registration fields from voting links#2907edulix wants to merge 13 commits into
edulix wants to merge 13 commits into
Conversation
10 tasks
|
# Conflicts: # packages/keycloak-extensions/voter-enrollment/src/main/java/sequent/keycloak/voter_enrollment/DeferredRegistrationUserCreation.java # packages/keycloak-extensions/voter-enrollment/src/test/java/sequent/keycloak/voter_enrollment/DeferredRegistrationUserCreationTest.java
Three independent defects each stopped `login_hint__*` parameters from
prefilling the Keycloak username field.
`parseLoginHints` iterated `URLSearchParams.entries()` and `Map.keys()`
with `for ... of`. The portal compiles with `target: "es5"` and no
`downlevelIteration`, so both loops became indexed loops over an iterator
whose `length` is `undefined`, and never ran a single iteration. Hints
were therefore always empty, so the portal took the plain login path and
left the hints in the redirect URI. The unit tests did not catch this
because `@swc/jest` builds them for `es2022`.
`createLoginUrl` and `createRegisterUrl` return `Promise<string>` in
keycloak-js 26, and were passed unawaited to `appendLoginHints`, which
threw `Invalid URL` and aborted the redirect. TypeScript reports this,
but the webpack build runs `ts-loader` with `transpileOnly`.
The voting portal login template dropped stock Keycloak's
`value="${(login.username!'')}"`, so the username field rendered empty
even when Keycloak had resolved the hint.
(cherry picked from commit 566bb5a)
Registration fields now decide how they accept a prefilled value through the `loginHintPrefillPolicy` user profile annotation: `EDITABLE` (the default when unannotated), `READ_ONLY` or `IGNORE`. An unrecognised value falls back to `IGNORE`, so a typo never prefills a field. `READ_ONLY` renders the field read-only and rejects a registration whose submitted value differs from the hint, since the rendered attribute is only a browser affordance. The redisplayed form restores the hint value, otherwise the voter is left with a rejected value in a field they can no longer edit. Text inputs use `readonly` rather than `disabled` so the value is still submitted; selects, radios and checkboxes are disabled and mirror their value in a hidden input. Both prefill paths share the same resolution, so the annotation applies to stock and deferred registration alike. (cherry picked from commit c68bd8d)
The login page is not rendered from the user profile, so login.ftl cannot read the loginHintPrefillPolicy attribute annotation: neither the profile bean nor the authentication session client notes are in its data model. Render a prefilled username read-only when the realm attribute loginHintUsernamePolicy is READ_ONLY, defaulting to EDITABLE. A username restored by remember me stays editable so the voter can still sign in as somebody else. This is a presentation-only lock. Keycloak still authenticates whichever username is submitted, which is the same guarantee as an unprefilled login page: the password decides which account is entered. Registration stores the value, so READ_ONLY stays enforced on the server there. (cherry picked from commit 45a94d3)
edulix
marked this pull request as ready for review
July 29, 2026 17:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Parent issue: https://github.com/sequentech/meta/issues/12617
Summary
Backports the validated login and registration prefill feature from main PR #2905 to
release/10.0.login_hint__<field>parameters on Voting Portal/loginand/enrollroutes and forwards them throughkeycloak-jswithout replacing OIDC state, nonce, or PKCE.url_encodeHandlebars helper.Stable Backport
This branch replays the nine v10-relevant validated commits from #2905 onto
release/10.0. The main-only Release 9.5 migration-note commit is intentionally omitted because the stable v10 branch does not contain the 9.5 release-note page or a current release-notes section. Migration and realm rollout instructions remain in the backported Docusaurus operator/developer documentation.Security
Hints remain editable, untrusted convenience data. The implementation enforces atomic bounds and encoding validation, scrubs valid and invalid hint parameters from browser history, excludes credentials and unmanaged/read-only/hidden/verification fields, preserves submitted POST values, and removes rendered notification content, recipients, and helper arguments from application and electoral-log telemetry.
Validation
@sequentech/ui-essentialsexport warnings.clean verifypassed in 1:00, including 15 voter-enrollment and 22 conditional-authenticator tests.cargo fmt --all -- --check, two focused Windmill tests, two focusedsequent-corehelper tests, and the established Windmill Clippy gate passed.Environment Limits
The five live Nightwatch flows require provisioned
PREFILL_*_URLrealms and were not executed locally. The final Keycloak container image layer remains blocked by Docker Desktop content-store I/O corruption; the complete Maven provider reactor passed locally with standalone Apache Maven.2026-07-29 Update: rebased on
release/10.0and synced with #2905Merged the current
release/10.0into this branch and replayed the three new validated commits from #2905. The branch was previously conflicting; it now merges cleanly.Brought in from
release/10.0: the 4-PIN structured credential login (#2909, #2912), the datafix reconciliation process (#2917), and the SonarQube workflow (#2792).Replayed from #2905:
🐞 Fix login hints never reaching the login form— three defects each independently stopped any prefill from reaching the login page.parseLoginHintsiteratedURLSearchParams.entries()andMap.keys()withfor ... of, which the portal'ses5target compiles into indexed loops over an iterator whoselengthisundefined, so the loop bodies never ran; the Jest suite could not catch it because@swc/jestbuilds tests fores2022.createLoginUrl/createRegisterUrlreturnPromise<string>inkeycloak-js26 and were passed unawaited toappendLoginHints, throwingInvalid URLand aborting the redirect; TypeScript reports it, but the Webpack build runsts-loaderwithtranspileOnly: true. The voting portal login template omitted stock Keycloak'svalue="${(login.username!'')}".✨ Add per-attribute login hint prefill policy— registration fields declare how they accept a prefilled value through theloginHintPrefillPolicyuser profile attribute annotation:EDITABLE(applied when absent, so existing realms are unaffected),READ_ONLY, orIGNORE, with an unrecognised value falling back toIGNORE.READ_ONLYis enforced on the server: a changed value is rejected withloginHintReadOnlyFieldModifiedand the redisplayed form restores the hint value.✨ Lock a prefilled login username from the login template— the login page is not rendered from the user profile and cannot read the annotation, sologin.ftllocks a prefilled username when the realm attributeloginHintUsernamePolicyisREAD_ONLY(defaultEDITABLE). No new authenticator and no browser-flow change. This login lock is presentation-only: Keycloak still authenticates whichever username is submitted, the same guarantee an unprefilled login page gives.Conflict resolutions
login.ftl: the username input keeps therelease/10.0structured-credential behaviour (autocomplete="<#if structuredCredential>username<#else>off</#if>"and thestructuredCredentialHasError || credentialFieldErrorinvalid state) and gains the login hintvalueand theusernameReadOnlyguard.LoginTemplateTest: both branches added this class. The threerelease/10.0structured-credential tests are preserved and the two login hint tests are added; all five pass against the merged template.DeferredRegistrationUserCreationand its test: additive constant and import conflicts resolved as a union of both sides.Validation on this branch
clean verifypassed, including 24 voter-enrollment tests and 18 sequent-theme tests (5LoginTemplateTest, 4StructuredCredentialAssetTest).maincounterparts.Closes sequentech/meta#12617.