Skip to content

Organization invitation: prefill the registration form with the first and last name stored on the invitation #55239

Description

@nkhorit

Enhancement Description

When an organization invites an address that has no account (POST /admin/realms/{realm}/organizations/{id}/members/invite-user with email, firstName and lastName), the first and last name are stored on the invitation (OrganizationInvitationModel), and the invitation email greets the recipient by them. But the registration form that the invitation's link opens starts with the email only: First name and Last name are empty, so the recipient has to type again what the inviting administrator already gave.

Seen in Keycloak 26.8.2; the code is the same on main.

Where the names are lost:

  • OrganizationInvitationResource.inviteUser creates the invitation with the names. createToken builds an InviteOrgActionToken carrying the email, the organization id and the invitation id (as the token id), but no names.
  • RegistrationPage.render parses that token and sets only email (with the organization name and the message header) as form attributes.
  • FreeMarkerLoginFormsProvider.createRegistration copies only that email attribute, or the login hint, into the form data.

Neither the token nor the form receives the names, so no theme can show them. The Server Administration Guide ("Inviting users") describes them as being for a more personalized email message only.

Value Proposition

WCAG 2.2 success criterion 3.3.7 Redundant Entry (Level A) requires information already provided in the same process to be auto-populated or available to select. A registration form opened from an invitation is part of the same process as the invitation, so today's empty fields fail it for every deployment that invites users with names. Accessibility conformance is a procurement requirement for many public-sector deployments.

Goals

  • The registration form opened from an organization invitation starts with the invitation's first and last name, when the invitation has them.
  • The recipient can still change them, and a form returned with a validation error keeps what the recipient typed.
  • The names are read from the invitation Keycloak already holds, only when it is still valid and matches the token's organization and email; nothing new is trusted from the request.

Non-Goals

  • Changing the invitation token's contents.
  • Prefilling other user profile attributes.
  • Any change to invitations of existing users (invite-existing-user).

Discussion

No response

Notes

A possible change. In RegistrationPage.render, once the token is parsed and the organization checked, read the invitation by the token id and pass its names to the form the way the email is passed:

OrganizationInvitationModel invitation = provider.getInvitationManager().getById(token.getId());
if (invitation != null && !invitation.isExpired()
        && organization.getId().equals(invitation.getOrganizationId())
        && token.getEmail().equalsIgnoreCase(invitation.getEmail())) {
    form.setAttribute(FIELD_FIRST_NAME, invitation.getFirstName());
    form.setAttribute(FIELD_LAST_NAME, invitation.getLastName());
}

Then in FreeMarkerLoginFormsProvider.createRegistration, beside the existing handling of email, copy the firstName and lastName attributes into the form data when the field is empty, so a form sent back with a validation error keeps what the user typed.

Steps to reproduce: enable organizations in a realm and create an organization; invite a new address with invite-user, giving firstName and lastName; open the link in the email; the First name and Last name fields are empty while the email is filled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/organizationsOrganizations — multi-tenancy, members, managed IdPs, domains, invitationskind/enhancementCategorizes a PR related to an enhancementstatus/labeled-by-botIssue type or area was assigned automatically by the triage botstatus/triageteam/core-iam

    Fields

    Value

    None yet

    Effort

    None yet

    Votes

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions