Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Resources are not loaded #33

Open
netmikey opened this issue Nov 1, 2020 · 4 comments
Open

Theme Resources are not loaded #33

netmikey opened this issue Nov 1, 2020 · 4 comments

Comments

@netmikey
Copy link
Contributor

netmikey commented Nov 1, 2020

The embedded spring boot keycloak server seems not to be able to load theme resources out of the box. I was trying to include this identity provider extension:

https://github.com/BenjaminFavre/keycloak-apple-social-identity-provider

In its documentation, it is referring to the Keycloak Deployer, which we don't have in this project's context (I guess?). So I just included the provider Jar in the classpath (Spring-Boot style). The provider showed up in the admin console's list of identity providers but when I chose it, I got a 404 error indicating a missing resource. Diving into the provider's code showed that some html files located in theme-resources/resources/partials/ should have been accessible but actually aren't.

After I found the corresponding part of the Keycloak documentation, I wrote a quick and dirty ThemeResourceProvider that would just look up the resource in the classpath underneath the documented theme-resources/resources/ prefix and voila: it worked for the html files.

The identity provider still seems to be missing its message resources though, but there's no such thing as a MessageResourceProvider so I don't think I can monkey-patch that one in.

TL;DR: the mechanism that loads theme resources (resources, messages and probably also templates) described here doesn't seem to work in the embedded spring boot keycloak server.

@nigredo-tori
Copy link

The identity provider still seems to be missing its message resources though, but there's no such thing as a MessageResourceProvider so I don't think I can monkey-patch that one in.

I vaguely remember poking this code for a similar reason, but I can't provide you with a ready-made solution or explanation. I can say that it's the responsibility of the Theme to provide messages, as can be seen here - so, as a start, you might want to figure out what Theme subclass is used for your theme, where it is created, and how to bend that code to your will. A debugger can be useful to figure out the IoC logic. My general impression was that the use case of loading custom resources/themes/plugins from the application classpath (as opposed to the deployment module classpath) wasn't really considered when Keycloak was built, so you might need to inject more than one SPI to achieve your goal.

@nigredo-tori
Copy link

nigredo-tori commented Nov 2, 2020

Actually, scratch that. I've reread your post, as well as my own code on the matter. You're attempting to use theme resources - a (confusingly named) mechanism to inject resources, such as message bundles and HTML for a plugin, regardless of the selected theme. This is exactly the use case I had, and for me it was enough to add this class (in Scala, but you get the picture):

final class EmbeddedThemeResourceProviderFactory
    extends ClasspathThemeResourceProviderFactory(
      "embedded-resources",
      classOf[EmbeddedThemeResourceProviderFactory].getClassLoader
    )

, and wire it up in META-INF/services/org.keycloak.theme.ThemeResourceProviderFactory. I'm not sure why that doesn't work in your case.

@netmikey
Copy link
Contributor Author

netmikey commented Nov 2, 2020

Hey @nigredo-tori, thanks for rechecking the ticket! Your solution works perfectly, thanks a lot! The reason it wasn't working for me is that I hadn't looked and so didn't know about the ClasspathThemeResourceProviderFactory class. So I implemented something quick and sketchy myself that was, of course, not complete.

Nevermind: it works with the EmbeddedThemeResourceProviderFactory implementation above.

@thomasdarimont I think this is something the embedded-spring-boot-keycloak-server should come with out of the box, since it works that way in Wildfly out of the box too, what do you think?

@thomasdarimont
Copy link
Owner

I did look into this a while ago in this branch support-theme-components where I tried to adapt the theme resource loading to the mechanisms that are used by Keycloak on wildfly.

I'll try to give this another spin on the weekend.

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

No branches or pull requests

3 participants