kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Contribute sign-in login options as data through a user_auth backend hook

Open rtibbles opened this issue 5 months ago • 3 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

External auth plugins contribute login options to the sign-in page (the OIDC client's button), but a plugin's button never renders — the registry lives outside cross-bundle webpack externals. The fix that made it render moved the registry into the core JS API, a plugin-specific detail in a global core contract.

Move the mechanism into user_auth: login options are contributed as data through a backend hook, delivered on the existing plugin_data channel. Noop when user_auth is inactive; nothing login-specific in core.

Complexity: Medium Target branch: develop

Context

Current mechanism

  • packages/kolibri-common/utils/loginComponents.js — an array with a .register() method.
  • AuthBase.vue renders [...loginComponents] via <component :is>.
  • A plugin injects its login bundle via UserAuthSyncHook (user_auth-owned) → user_auth.html's {% user_auth_assets %}.

Why the button never renders

  • Cross-bundle externals cover only the core kolibri package's exports. kolibri-common isn't covered, so each independently-built bundle gets a private copy of the array; the plugin's .register() never reaches AuthBase's copy.

Constraints on the fix

  • CSP forbids inline scripts — the backend can't inject a <script> to register.
  • plugin_data already reaches the frontend as inert <template data-plugin> JSON (kolibri/core/webpack/hooks.py), read via kolibri-plugin-data — CSP-safe.

The Change

A login option is data, not behaviour: the OIDC button is a KExternalLink to /oidcauthenticate/ with a label, SVG icon, and button appearance — no client-side logic.

  • user_auth defines a backend hook (e.g. LoginItemHook). A plugin registers a subclass declaring: label (resolved server-side via Django i18n), login URL, icon static-asset URL, button appearance.
  • user_auth's plugin_data aggregates registered items into loginItems, delivered on the existing <template data-plugin> channel.
  • AuthBase.vue reads plugin_data.loginItems and renders one KExternalLink per item; user_auth owns the presentation.
  • Remove kolibri-common/utils/loginComponents.js and the <component :is> rendering.
  • Convert the OIDC client plugin to the hook and remove its frontend.
  • Bump the OIDC plugin's minimum Kolibri version (now depends on user_auth exposing the hook).

Out of Scope

  • The OIDC provider flow (OIDCProviderHook / oidcProviderEnabled) — unrelated concern, unchanged.
  • Login-item ordering/sorting — one item today; add a sort key when a second appears.
  • Arbitrary interactive login components — options are link/button data only.

Acceptance Criteria

Mechanism (user_auth)

  • [ ] user_auth exposes a backend hook that collects login options as data (label, login URL, icon URL, appearance).
  • [ ] Registered items surface in user_auth's plugin_data.loginItems, delivered via the <template data-plugin> channel — no inline script.
  • [ ] AuthBase.vue renders one KExternalLink per loginItems entry, styled by user_auth.
  • [ ] Labels display translated in the request's active language.
  • [ ] With no items registered, AuthBase.vue renders no login options.
  • [ ] When user_auth is inactive, the hook is a noop — undefined, no error.
  • [ ] packages/kolibri-common/utils/loginComponents.js and the <component :is> login rendering are removed.
  • [ ] Nothing login-item-specific is added to the core kolibri JS API.

OIDC client plugin

  • [ ] The login button renders on the sign-in page and completes login against a real provider.
  • [ ] The plugin contributes its option through the new hook; OIDCLogin.vue is removed.
  • [ ] The icon is served as a static asset and shown on the button.
  • [ ] The plugin's package.json is removed.
  • [ ] The LoginItem webpack bundle hook is removed.
  • [ ] The LoginItemInclusionHook bundle-inclusion hook is removed.
  • [ ] The plugin is removed from the pnpm workspace.
  • [ ] The browserslist config is removed.
  • [ ] pnpm-lock.yaml is regenerated.
  • [ ] The plugin no longer participates in the pnpm/webpack frontend build.
  • [ ] Minimum Kolibri version bumped to the release exposing the hook.

Testing

  • [ ] Backend: registering a login-item hook surfaces it in user_auth's plugin_data.loginItems.
  • [ ] Frontend: AuthBase.vue renders a link per loginItems entry, and none when empty.

References

  • PR #14955 — OIDC client migration; introduced then reverted the core-JS-API fix this replaces.
  • Design rationale — user_auth-owned hook, CSP constraint.

AI usage

AI-assisted with Claude Code — codebase exploration and issue drafting.

rtibbles avatar Jul 03 '26 19:07 rtibbles

Plan: Replace the broken kolibri-common/utils/loginComponents.js cross-bundle registry with a user_auth-owned backend hook (LoginItemHook) that delivers login-option data over the existing CSP-safe plugin_data channel, and migrate the OIDC client plugin to use it.

  • [ ] Define LoginItemHook
  • [ ] Aggregate LoginItemHook into UserAuthAsset.plugin_data
  • [ ] Simplify pass (Phase 1)
  • [ ] Render loginItems from plugin_data
  • [ ] Simplify pass (Phase 2)
  • [ ] Extract the icon to a static asset, register LoginItemHook, delete the old frontend
  • [ ] Bump the minimum Kolibri version and package the icon into the wheel
  • [ ] Simplify pass (Phase 3)
  • [ ] Drop pnpm workspace membership and regenerate the lockfile
  • [ ] Simplify pass (Phase 4) and final full-suite check

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Jul 03 '26 20:07 rtibblesbot

@rtibbles can i work on this issue as i see its has various parts

Dhirenderchoudhary avatar Jul 03 '26 22:07 Dhirenderchoudhary

Hi! 👋

Thanks so much for your interest! This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues. If there are no unassigned 'help wanted' issues available, please wait until new ones are added.

We really appreciate your willingness to help. 😊

Are you preparing for Google Summer of Code? See our GSoC guidelines.

learning-equality-bot avatar Jul 03 '26 22:07 learning-equality-bot