ThemeSelectorProviderFactory not used by keycloak 7

For whoever needs something like this in the future, including my future self.

In order to make your custom theme selector SPI actually work (might apply to other types of SPIs, interestingly not for UserStorageProviders though, those work just fine as per the documentation), you need to declare it as the default one so it takes over DefaultThemeSelectorProvider.

Otherwise, although your custom provider is initialized, the create method in the Provider Factory class is never called.

In order to declare your Theme Selector as the default one, instead of declaring it like this (as documented here):

<spi name="themeSelector">
       <provider name="my-theme-selector-provider" enabled="true"/>
</spi>

You should declare it like this:

<spi name="themeSelector">
       <default-provider>my-theme-selector-provider</default-provider>
       <provider name="my-theme-selector-provider" enabled="true"/>
</spi>

and voilá.

The main cause of this problem is perhaps that Keycloak doesn’t seem to have a section in the admin interface to specify that your custom SPI should be used instead of the default one (or at least I haven’t found any).

Worth mentioning that I did all this on Keycloak 11, not in version 7.

4 Likes