p2-inc / keycloak-orgs

Single realm, multi-tenancy for SaaS apps
https://phasetwo.io
Other
389 stars 66 forks source link

unable to send invitation email; template not found #22

Closed tomschulze closed 1 year ago

tomschulze commented 1 year ago

Thanks for making keycloak-orgs open source. I am testing the invitation feature to get an idea how the flow works. However, I am struggling sending invitations. What I am trying to achieve is to send an invitation link to a non-user who can then create an account by clicking on the link.

I use the docker image quay.io/phasetwo/phasetwo-keycloak:20.0.0-alpha. The email settings for my realm are configured and I do receive the keycloak test email.

Now, when sending an invitation with this API call

http -A bearer -a $tkn  localhost:4000/realms/myrealm/orgs/59b6702e-4296-4a43-b119-211fd2429e13/invitations email="myemail" send=true

# HTTP/1.1 201 Created

the keycloak server logs the following error:

WARN  [io.phasetwo.service.resource.InvitationsResource] (executor-thread-31) Unable to send invitation email: java.lang.reflect.InvocationTargetException

[...]

Caused by: org.keycloak.email.EmailException: Failed to template email
    at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.processTemplate(FreeMarkerEmailTemplateProvider.java:246)
    at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send(FreeMarkerEmailTemplateProvider.java:261)
    ... 56 more
Caused by: org.keycloak.email.EmailException: Failed to template plain text email.
    at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.processTemplate(FreeMarkerEmailTemplateProvider.java:234)
    ... 57 more
Caused by: org.keycloak.theme.FreeMarkerException: Failed to process template text/invitation-email.ftl
    at org.keycloak.theme.freemarker.DefaultFreeMarkerProvider.processTemplate(DefaultFreeMarkerProvider.java:52)
    at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.processTemplate(FreeMarkerEmailTemplateProvider.java:232)
    ... 57 more
Caused by: freemarker.template.TemplateNotFoundException: Template not found for name "text/invitation-email.ftl".

Do I have to create the template myself?

xgp commented 1 year ago

@tomschulze thanks for the bug report. This is an accidental-ish omission. For a few versions, Keycloak had a bug where it no longer loaded resources from the theme-resources directory of extensions. Because of this, it wasn't included. It seems to work in 20.0.0, so I'll add it back. I'll leave this open until I have the time to do it in the next couple of days.

xgp commented 1 year ago

The templates are in the current release and docker image.