Skip to content

Application-initiated actions: kc_action on the challenge endpoint - #41

Merged
pnzrr merged 6 commits into
mainfrom
jp/kc-action
Nov 22, 2026
Merged

pnzrr merged 6 commits into
mainfrom
jp/kc-action

Conversation

@pnzrr

@pnzrr pnzrr commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

A signed-in app can start a required action on request — first use: Change password from an app's settings, with the user proving who they are first. Design: spec/21. SDK support follows in a separate PR (spec/21 D6).

How it works. kc_action=<alias> on the challenge endpoint (usually with the post-login auth_session, i.e. a step-up) is copied to Keycloak's kc_action client note, so Keycloak's own AIA rules apply:

  • Re-authentication when the user session's authentication is older than the action's Maximum Age of Authentication (for Update Password also the password policy's maxAuthAge; default 300 s), or when the app sends max_age / prompt=login. Operators set the default in the admin console; apps can only make it stricter.
  • Within that age (and without a higher acr_values) the step-up skips the flow and goes straight to the action, like a browser's identity cookie. Without this, a flow without LoA conditions would re-run every factor and the realm setting would never apply.
  • The action runs even when nothing is pending; it must be enabled and support application initiation (executeAction's checks). Today: native-update-password.
  • The user may cancel (action=skip) unless the action is also pending on the user.
  • The 200 body carries kc_action_status: success, cancelled or error.

Sign out other devices. update_password offers logout_other_sessions (param true as the suggested default; optional answer field, absent = false so older SDKs behave as before). It ends the user's other online and offline sessions and keeps the current one; Keycloak's AuthenticatorUtil.logoutOtherSessions would also end the step-up's own session, so the action has its own implementation.

Fix along the way. RequiredActionDriver recorded success/skip statuses under the native provider id, so a substituted action (e.g. UPDATE_PASSWORD → native-update-password) never reported a kc_action_status.

Tests.

  • New KcActionIT (5): change right after login without re-auth + other session ended / own session kept; realm maxAuthAge(0) forces re-auth; max_age=0 + cancel keeps the password; non-initiatable / unknown actions report error; no status without kc_action.
  • Locally: KcActionIT, RequiredActionsIT, StepUpIT, EnrolOnFirstLoginIT, PinIT — 28 tests pass.
  • Transcripts: the five KcActionIT ones added; RequiredActionsIT.carolUpdatesHerPasswordInBand re-recorded (the descriptor gained logout_other_sessions). iOS core (125 tests) and Android core replay suites pass against them.

Docs: spec/03 (§2.1, §3.1, §4.11, §4.12, §5), spec index, docs/protocol-and-flows.md (new Application-initiated actions section).

A signed-in app can start a required action on request (spec/21), e.g. a password change from its settings. kc_action is copied to Keycloak's kc_action client note, so Keycloak's own rules apply: re-authentication when the action's maximum authentication age has passed (or max_age / prompt=login), the action runs even when nothing is pending, and an unconfigured alias reports error.

- Step-up with kc_action within the action's max age and without a higher level skips the flow and goes straight to the action, like a browser's identity cookie (also on flows without LoA conditions).
- RequiredActionDriver applies executeAction's checks (initiated-action support, enabled), makes an app-initiated action skippable unless it is also pending on the user, and records kc_action_status under the requested alias (success and skip statuses were recorded under the native id, so substituted actions never reported one).
- The 200 body carries kc_action_status (success, cancelled, error).
- native-update-password supports application initiation and offers logout_other_sessions, which ends the user's other online and offline sessions but keeps the current one (Keycloak's helper would also end the step-up's own session).
- KcActionIT plus transcripts; carol's update_password transcript re-recorded for the new param. spec/21, spec/03 and docs updated.
…the SDKs

An SDK always exchanges the code after a 200; the scenarios now sign in the way an app does. The status-free login check moved into the shared sign-in.
- Split alias:parameter into kc_action and kc_action_parameter like AuthorizationEndpoint (delete_credential:<id>, idp_link:<alias>, webauthn-register:skip_if_exists).
- An action without a native variant continues through redirect_to_web with kc_action in the stored PAR request, so Keycloak's page runs it and the browser redirect carries kc_action_status (it was dropped, so the action never ran).
- native-verify-email, native-configure-pin and native-passkey-register allow application initiation.
- KcActionIT: parameter split, VERIFY_EMAIL cancel, UPDATE_PROFILE through the browser with kc_action_status=success on the callback; transcripts. spec/21, spec/03 and docs updated.
@pnzrr
pnzrr merged commit 401bb5d into main Nov 22, 2026
14 checks passed
@pnzrr
pnzrr deleted the jp/kc-action branch November 22, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants