Repository navigation
Conversation
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>
This was referenced Sep 15, 2026
Closed
Contributor
There was a problem hiding this comment.
🟡 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
UiScriptProviderSPI 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()) |
Contributor
Author
|
Superseded by #54586, which takes a simpler ES-module approach ( |
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.
Summary
UiScriptProvider/UiScriptProviderFactorySPI for declarative UI extensions backed by JavaScript custom elements/admin/realms/{realm}/ui-scripts/{providerId}/script.jswith admin authenticationtests/custom-providersMotivation
UiPageProviderandUiTabProvidercover 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
./mvnw -pl server-spi-private,services,tests/custom-providers -am -DskipTests compile--features=declarative-uiand deploytests/custom-providersJARexample-ui-scriptappears in Configure and loads the custom elementCloses #52777