Quickly Customize Keycloak Using SPIs

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ธ.ค. 2024

ความคิดเห็น • 16

  • @code-215
    @code-215  ปีที่แล้ว

    Thank you for watching this video. Please feel free to buy me a coffee www.buymeacoffee.com/Code215

  • @bartomiej6824
    @bartomiej6824 3 หลายเดือนก่อน

    Very good and very helpful video, thank you so much, you doing good work! Have a nice day!

  • @Kitty-w6q7p
    @Kitty-w6q7p 3 หลายเดือนก่อน

    Hi! Thank for tutorial, and i have a question:
    lets assume i want to separate user and member entities so that user is keycloak user, stored in kc database, and member is an entity, which is managed by 'members' microservice of my backend project for example. User is used for authentication, and member is used for complex authorization at microservice side. Also, User has attribute 'member_id' to associate with a specific member. When user registers himself with registration form, keycloak should invoke 'members' microservice to create a member with name and surname specified in registration form. The obtained id of created member should be stored in 'member_id' attribute of keycloak user. This attribute will be put into access tokens so that microservice can implement any authorization process. I think it is possible to implement such logic with EventListenerProvider, but what if 'members' endpoint invokation fail? For example, it returned code 400 or 500. Obviously, in this case the whole registration process should fail and no user in KC should be stored, otherwise we have data inconsistency. How to solve this problem?

  • @K4dryl
    @K4dryl ปีที่แล้ว +3

    Could you add a github link?

  • @treynight
    @treynight ปีที่แล้ว +1

    I can get this to work when creating a user manually while logged in, however, I'm having difficulty in getting this to occur when doing a self-registration. Any suggestions on this?

    • @code-215
      @code-215  ปีที่แล้ว

      Not quite following. What difficulty are you having?

    • @treynight
      @treynight ปีที่แล้ว

      @@code-215 This only seems to work when someone is logged in and creating a new user. Keycloak allows for self-registration, which this doesn't appear to work for. Do you know if there's a way to add an event listener to the creation of a user from there vs someone like an admin manually adding a user?

    • @code-215
      @code-215  ปีที่แล้ว +1

      @@treynight You'd put that code in the onEvent(Event event) method. That's where non-admin events go. Event has an EventType enum which has "REGISTER" defined so you'd check for that to determine if the event is a user registration event.

    • @treynight
      @treynight ปีที่แล้ว

      @@code-215 Awesome, got it. Thanks!

  • @francisoladosu9643
    @francisoladosu9643 5 หลายเดือนก่อน

    Hi, thanks for the video. Please is it possible to have access to those events in the java code and then maybe perform some operation based on the event type. In my case, when a User is registered, i want to call a createUserWallet method in my project. How do i go about it? Currently the logs only print in Docker, i need a way to access those values in the Java code. Thanks in anticipation.

    • @code-215
      @code-215  5 หลายเดือนก่อน

      Yes. When the event happens send a HTTP request to an endpoint in your project. That endpoint then calls createUserWallet

    • @francisoladosu9643
      @francisoladosu9643 5 หลายเดือนก่อน

      @@code-215 Thanks for your response. But I have tried this and it didn’t work. The issue I’m having is the the onEvent method isn’t getting triggered so all codes within it isn’t working. I tried printing the eventType to the console, nothing shows up, but for some reasons When I use docker logs I see all the events in real-time. But it’s not being picked up in my onEvent method.

    • @code-215
      @code-215  5 หลายเดือนก่อน

      If you followed the steps in this tutorial it should work. I think you missed a step. Verify that you've added the SPI to Keycloak and saved it(as shown at 10:35). Make sure you've implemented the right classes and methods. The onEvent() you override should be the one with the AdminEvent parameter not Event parameter. Make sure your folder structure is correct. Verify that you have followed all the steps in this tutorial.

    • @Kitty-w6q7p
      @Kitty-w6q7p 3 หลายเดือนก่อน

      @@code-215 bro, but what about if createUserWaller fails? There is an uncosistency of data, when user is created within keycloak db, but wallet doesn't exist.

  • @GautamKumar-xq8ve
    @GautamKumar-xq8ve ปีที่แล้ว

    @code215 couple of Questions:
    1) Will the logic change say if i am using Keycloak 16 or keycloak 21.1.1
    2) I have a requirement where on keycloak register screen i need to add some additional fields and then send all the data to an external API thorough SPI. Can you suggest how to build jar file through scratch
    Also, Do you have the github link for above SPI shown in video

    • @code-215
      @code-215  ปีที่แล้ว

      1)No, both versions have event listeners in their libraries.
      2) Yes, this is possible. The additional fields you add will be in the "attributes" field of the User. You can find those details here: www.keycloak.org/docs/latest/server_development/#registration-page
      I'll add Github link later