8000 Add UiScriptProvider SPI for custom element admin console extensions by edewit · Pull Request #52778 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Add UiScriptProvider SPI for custom element admin console extensions - #52778

Closed
edewit wants to merge 1 commit into
keycloak:mainfrom
edewit:issue-52777-ui-script-provider
Closed

edewit wants to merge 1 commit into
keycloak:mainfrom
edewit:issue-52777-ui-script-provider

Conversation

@edewit
@edewit edewit commented Sep 15, 2026
Copy link
Copy Markdown
Contributor

Summary

  • Add UiScriptProvider / UiScriptProviderFactory SPI for declarative UI extensions backed by JavaScript custom elements
  • Serve provider scripts from /admin/realms/{realm}/ui-scripts/{providerId}/script.js with admin authentication
  • Load scripts in the Admin Console, add sidebar navigation, and mount custom elements with realm context
  • Include an example provider in tests/custom-providers

Motivation

UiPageProvider and UiTabProvider cover form-based extensions. This adds a third option for richer client-side UI implemented as web components, continuing the work discussed in #24805.

Test plan

  • Build with ./mvnw -pl server-spi-private,services,tests/custom-providers -am -DskipTests compile
  • Start server with --features=declarative-ui and deploy tests/custom-providers JAR
  • Verify example-ui-script appears in Configure and loads the custom element
  • Verify script endpoint requires authentication

Closes #52777

Introduce a third declarative UI extension SPI that lets providers bundle
JavaScript registering a custom element. The Admin Console serves the script
via an authenticated admin endpoint, adds navigation, and passes realm context
to the mounted element.

Closes keycloak#52777

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Script reload, tag validation, and cache invalidation issues can prevent extensions from loading correctly or keep stale code active.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds a declarative UI SPI for authenticated, custom-element-based Admin Console extensions.

Changes:

  • Introduces the UiScriptProvider SPI and validation.
  • Adds script-serving and Admin Console loading/navigation.
  • Provides an example custom-element provider.
File summaries
File Description
tests/custom-providers/src/main/resources/ui-scripts/example-widget.js Defines the example custom element.
tests/custom-providers/src/main/resources/META-INF/services/org.keycloak.services.ui.extend.UiScriptProviderFactory Registers the example factory.
tests/custom-providers/src/main/java/org/keycloak/tests/providers/ui/ExampleUiScriptProviderFactory.java Configures the example extension.
tests/custom-providers/src/main/java/org/keycloak/tests/providers/ui/ExampleUiScriptProvider.java Implements the example provider.
services/src/main/resources/META-INF/services/org.keycloak.services.resources.admin.ext.AdminRealmResourceProviderFactory Registers the script endpoint.
services/src/main/java/org/keycloak/services/resources/admin/UiScriptsResource.java Serves authenticated scripts.
services/src/main/java/org/keycloak/services/resources/admin/UiScriptsRealmAdminProvider.java Exposes the realm resource.
server-spi-private/src/main/resources/META-INF/services/org.keycloak.provider.Spi Registers the new SPI.
server-spi-private/src/main/java/org/keycloak/services/ui/extend/UiScriptSpi.java Defines SPI metadata.
server-spi-private/src/main/java/org/keycloak/services/ui/extend/UiScriptProviderUtils.java Validates extension declarations.
server-spi-private/src/main/java/org/keycloak/services/ui/extend/UiScriptProviderFactory.java Defines factory metadata.
server-spi-private/src/main/java/org/keycloak/services/ui/extend/UiScriptProvider.java Defines the provider contract.
js/apps/admin-ui/src/ui-script/useScriptLoader.ts Fetches and executes provider scripts.
js/apps/admin-ui/src/ui-script/UiScriptHost.tsx Mounts custom elements with context.
js/apps/admin-ui/src/ui-script/types.ts Defines extension context types.
js/apps/admin-ui/src/ui-script/ScriptPage.tsx Renders extension pages.
js/apps/admin-ui/src/ui-script/routes.tsx Defines extension routing.
js/apps/admin-ui/src/ui-script/constants.ts Defines the provider type key.
js/apps/admin-ui/src/routes.tsx Registers extension routes.
js/apps/admin-ui/src/PageNav.tsx Adds extension navigation.
js/apps/admin-ui/src/environment-types.ts Exposes the authentication URL.
Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

await new Promise<void>((resolve, reject) => {
script!. => resolve();
script!. => reject(new Error("Script failed to load"));
document.head.appendChild(script!);
Comment on lines +3 to +15
import java.util.regex.Pattern;

public final class UiScriptProviderUtils {

private static final Pattern TAG_NAME_PATTERN = Pattern.compile("[a-z][a-z0-9]*(-[a-z0-9]+)+");

private UiScriptProviderUtils() {
}

public static void validateTagName(String tagName) {
if (tagName == null || !TAG_NAME_PATTERN.matcher(tagName).matches()) {
throw new IllegalArgumentException("Invalid custom element tag name: " + tagName);
}
Comment on lines +79 to +80
.header(HttpHeaders.ETAG, contentEtag)
.cacheControl(CacheControlUtil.getDefaultCacheControl())
@edewit
edewit commented Nov 3, 2026
Copy link
Copy Markdown
Contributor Author

Superseded by #54586, which takes a simpler ES-module approach (getUrl() + dynamic import) instead of classpath custom-element script serving.

@edewit edewit closed this Nov 3, 2026
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.

Add UiScriptProvider SPI for custom element admin console extensions

2 participants

0