vymalo/keycloak-webhook

Webhooks fail with --features=declarative-user-profile

Opened this issue · 3 comments

After experimental feature: declarative-user-profile are enabled, and a custom attribute is added to the user profile, webhooks aren't sent. An error message is logged on the console instead:
"Could not send webhook: java.lang.UnsupportedOperationException: responseBody currently only supports JSON body"

This might be related to the static schema defined in openapi/webhook.open-api.yml, and perhaps to OpenAPITools/openapi-generator#2944.

Can you please provide steps to reproduce it? I'm interested in fixing it

Here is details about the error i have the same issue :)

The error in keycloak logs :

2024-05-31 16:41:03,928 ERROR [com.vymalo.keycloak.webhook.WebhookEventListenerProvider] (executor-thread-2) Could not send webhook: java.lang.UnsupportedOperationException: responseBody currently only supports JSON body.
        at com.vymalo.keycloak.openapi.client.handler.WebhookApi.sendWebhookWithHttpInfo(WebhookApi.kt:400)
        at com.vymalo.keycloak.openapi.client.handler.WebhookApi.sendWebhook(WebhookApi.kt:61)
        at com.vymalo.keycloak.webhook.service.HttpWebhookHandler.sendWebhook(HttpWebhookHandler.kt:21)
        at com.vymalo.keycloak.webhook.WebhookEventListenerProvider.send(WebhookEventListenerProvider.kt:86)
        at com.vymalo.keycloak.webhook.WebhookEventListenerProvider.onEvent(WebhookEventListenerProvider.kt:23)
        at org.keycloak.events.EventBuilder.sendNow(EventBuilder.java:266)
        at org.keycloak.events.EventBuilder.send(EventBuilder.java:253)
        at org.keycloak.events.EventBuilder.success(EventBuilder.java:221)
        at org.keycloak.services.managers.AuthenticationManager.finishedRequiredActions(AuthenticationManager.java:1031)
        at org.keycloak.authentication.AuthenticationProcessor.authenticationComplete(AuthenticationProcessor.java:1157)
        at org.keycloak.authentication.AuthenticationProcessor.authenticationAction(AuthenticationProcessor.java:1019)
        at org.keycloak.services.resources.LoginActionsService.processFlow(LoginActionsService.java:365)
        at org.keycloak.services.resources.LoginActionsService.processAuthentication(LoginActionsService.java:336)
        at org.keycloak.services.resources.LoginActionsService.authenticate(LoginActionsService.java:328)
        at org.keycloak.services.resources.LoginActionsService.authenticateForm(LoginActionsService.java:393)
        at org.keycloak.services.resources.LoginActionsService$quarkusrestinvoker$authenticateForm_32b8e198ac3110abd1d5774e83a4cf87858129f4.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:582)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:840)

Here is the docker-compose configuration for my local setup :

keycloak:
    image: quay.io/keycloak/keycloak:latest
    environment:
      KC_DB: "XXXXX"
      KC_DB_PASSWORD: "XXXX"
      KC_DB_URL: "XXXX"
      KC_DB_USERNAME: "XXX"

      KEYCLOAK_ADMIN: "admin"
      KEYCLOAK_ADMIN_PASSWORD: "admin"
      WEBHOOK_HTTP_BASE_PATH: "http://node:3000/api/webhooks/keycloak" // node:3000 is my local nodejs api
      WEBHOOK_EVENTS_TAKEN: "LOGIN,REGISTER"
      WEBHOOK_HTTP_AUTH_USERNAME: "admin"
      WEBHOOK_HTTP_AUTH_PASSWORD: "password"
    ports:
      - 8443:8080
    volumes:
      - ./providers:/opt/keycloak/providers
    command:
      - start-dev

I just started the my api, my frontend (vuejs app) and my keycloak but when i login this error happen and nothing is sent to the webhook url. Do you need anything else ?

Okay i think i figured out what was the problem, the webhook endpoint response need to be JSON. I was sending the result with res.sendStatus(200) but it work when i do the result with json response res.json({ success: true })