Тёмный

KEYCLOAK Implementing Custom User Storage Provider (in-depth) | Niko Köbler (@dasniko) 

Niko Köbler - Expert for Keycloak IAM & SSO
Подписаться 5 тыс.
Просмотров 34 тыс.
50% 1

Опубликовано:

 

21 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 121   
@scout23DF
@scout23DF 2 года назад
Awesome! Extremely helpful ! Thanks, Niko Köbler!
@learnthroughcoding5554
@learnthroughcoding5554 Год назад
Awesome video! helpfull !... please provide a video for the custom ISP in Keycloak
@enoosnajekliw
@enoosnajekliw Месяц назад
Hello Niko, Thank you for these helpful examples. Trying out the PeanutsUserProvider tests I got an error in the test testLoginAsUserAndCheckAccessToken. The access token payload does not contain the requested attributes, if I switch to the id token however, the test succeeds. Am I missing something? Thank you in advance. Mrs. Wilke Jansoone
@RomainHerault-q6n
@RomainHerault-q6n 8 месяцев назад
Thanks for this awesome tutorial! Is that possible to store default users in my own database but let Keycloak manage credentials (password, etc) ?
@EdmilsonSantana-tx3ww
@EdmilsonSantana-tx3ww Год назад
Hi Niko, thanks for the explanation of your example provider. I'm just finishing to implement a redis provider. My use case only requires user to be imported to KC local storage but could easily be extended to other use cases.
@francescobagnoli2637
@francescobagnoli2637 2 года назад
Great, thank you for these awesome keycloak tutorial! Can we have a tutorial on how to implement mandatory fields in keycloak registration or in idp-login update profile?
@dasniko
@dasniko 2 года назад
Have a look into the declarative User Profile SPI (still preview feature).
@mohamedmatrouh6284
@mohamedmatrouh6284 2 года назад
Thank you, I really appreciate your efforts
@TaniaKampana
@TaniaKampana 2 месяца назад
Is there any example for implementation of UserBulkUpdateProvider, ImportedUserValidation and ImportSynchronization?
@thavathrath7022
@thavathrath7022 2 года назад
Great, it's helpful. many thanks 😊🙏
@francois-xaviervits6051
@francois-xaviervits6051 2 года назад
Thanks for the video. It was very helpful. Did you plan to make a video based on the new api Map Storage API that replace the deprecated User Storage SPI in the latest keycloak version ?
@tony_0088
@tony_0088 8 месяцев назад
Awesome video. I've seen many of your videos, and you are up there among the best regarding Keycloak. In doing a User Storage Provider similar to this here, I've noticed that every time keycloak loads a "federated user" data (for example an via Api), that same user data is loaded many times, which translates into many equal requests hitting the server containing the "federated users". In case this a known phenomenon could you please point me towards relevant documentation where I can learn more about avoiding this? Keep up the awesome work, and just so that you know, your material helped me a lot in implementing custom 2FA checks, and custom authentication flows.
@dasniko
@dasniko 7 месяцев назад
See e.g. here: github.com/dasniko/keycloak-extensions-demo/blob/6b75adb50016f614f7c1c5c8b7a0c0784884e5d0/peanuts-userprovider/src/main/java/dasniko/keycloak/user/peanuts/PeanutsUserProvider.java#L46 Although I'm using currently a more advance, but also more complex version, the approach is the same by "caching" the user which is found once during one transaction and thus reduce the calls to external storage.
@tony_0088
@tony_0088 7 месяцев назад
@@dasniko Awesome thanks! I did think about caching the results too, but I just wanted to confirm that that is the natural behaviour and not some kind of rookie mistake I was incuring into XD. As allways, your content is AAA and extremely didactic (which is particularly helpful considering the official doc barely scratches KC possiblities). Again, I'm truly thankful, your work is amazing.
@miguemc83
@miguemc83 Год назад
Thank you very much for this video. I have a keycloak realm which only accepts x509 authentication. Is there any way to implement a x509 custom user provider? I need to get the userdata from a remote web service which accept only signed (with the user certificate) requests
@שרהקצב-י4פ
@שרהקצב-י4פ Год назад
Hi Niko, thanks for your explanation. is it possible to create custom provider for groups search, in order to make the search case-insensitive?
@CD-vo6nj
@CD-vo6nj Год назад
Hi. Extremely useful example. Thanks. Do you know if it is possible to map client roles as well as realm roles. If I return them both from getRoleMappingsInternal they all get added as realm roles (even if I set isClientRole to true in the RoleModel)and getClientRoleMappings doesn't seem to get called.
@vb1966
@vb1966 Год назад
Thank you very much for this video and popularization of providers for keycloak. You are my teacher :). Your Flintstone example helped me a lot to start implementing my first provider, but I had to go further with it. Namely, to implement role management, adding roles to the realm from storage, assigning, deleting mappings. The only thing that is not solved for me is the interception of the role creation event in the realm in order to instantly synchronize it with the jdbc repository. Thanks for your experience
@toonlenkens3650
@toonlenkens3650 Год назад
11:47
@ismailbouaziz3175
@ismailbouaziz3175 2 года назад
Thank you for this tutorial, just I want to know which is the best embedded keycloak or standalone keycloak for this solution and how I have to make my choice.
@dasniko
@dasniko 2 года назад
There is no embedded Keycloak.
@savagetadow
@savagetadow Год назад
Just started the learning path regarding this thread and would be very grateful for a hint on how to install the custom user federation. I know that the JAR package should be in the providers folder, but how to create this JAR file? I tried to use the default command in cmd, but it didn't work for me( Get nothing after "kc.bat build" command(
@mingli9563
@mingli9563 2 года назад
This channel is so great!
@sunnatillaaxakalov5784
@sunnatillaaxakalov5784 2 года назад
Thanks, good video. Do you know how to distinguish credential types ? In this video used PasswordCredentialType, how to realize PincodeCredentialType, FingerPrintCredentialType, and send request for authorization via Authzclient ?
@sunnatillaaxakalov5784
@sunnatillaaxakalov5784 2 года назад
@dasniko, could you suggest some direction to resolve problem ?
@timafun
@timafun Год назад
Is it possible to create some kind of User Attribute Provider attributes from which we can map to LDAP/AD users ?
@hamza201183
@hamza201183 7 месяцев назад
Are attributes only of type String? Or can it be any object? Imagine the scenario where the peanut user contains also objects (like a list of products, a "one-to-many" relationship to products). Can the user SPI handle this use-case? Vielen Dank!
@dasniko
@dasniko 7 месяцев назад
Internally, user attributes are a MultivaluedMap, so an attribute key can have multiple values, each of them are stored internally as a string, also the user attribute type is string. If the "string" value is actually a numeric value, it can be mapped to the token(s) as a number, but this is not related to the user storage, this is token mapper related.
@hamza201183
@hamza201183 7 месяцев назад
@@dasnikoMany thanks for your quick answer. I will consider and study this. I'm still new to Keycloak extensions.
@andrescorrea945
@andrescorrea945 9 месяцев назад
Hi Niko, thanks for the explanation, my question now is how we can combine it with 2FA.
@dasniko
@dasniko 9 месяцев назад
The same way you doing it with users from Keycloak's own database, there's no difference. The User Storage SPI ist for user data, not for authentication. If you have stored the 2FA data also in an external source, you'll have to implement the methods for validating/updating the credentials properly.
@mikhaildorokhovich1804
@mikhaildorokhovich1804 Месяц назад
Awesome Niko!!!
@DoisKoh
@DoisKoh Год назад
Can you implement the User Storage Provider without handling credentials? Can I leave that to Keycloak to deal with and I just store the User's ID, username, email... ?
@dasniko
@dasniko Год назад
Yes, that's possible. Just don't implement the "CredentialInput..." interfaces.
@iasminconstantin3825
@iasminconstantin3825 2 года назад
How can SwaggerUI can be attack to SPI implementation, or this is possible?
@odjoktiafrapdevelopper989
@odjoktiafrapdevelopper989 Год назад
Very good tutorial video! Your different tutorials about keycloak helped me to understand how to use this tool. Regarding the user storage provider, I downloaded your jar file and imported it in keycloak by providing the link to a replication of your apis in mockoon but the connection fails. Please could you tell me what this is due to. Thanks
@dasniko
@dasniko Год назад
As I don't know what you did, I cannot tell you anything. Please understand that I cannot give support through RU-vid comments. Thanks.
@javadezaz8220
@javadezaz8220 2 года назад
Hello Niko Köbler. How I can use Keycloak reset password and forget password feature in my react admin panel?
@elbozo5723
@elbozo5723 Год назад
hey niko, is there any chance you could do a video on how to customize the keycloak v2 theme?
@izac6462
@izac6462 5 месяцев назад
Do you think its possible to add a button to test the connection just like the ldap privider?
@dasniko
@dasniko 5 месяцев назад
generally yes, but this requires to add custom resources to the admin theme and currently the admin theme can only be extended by forking it and maintaining a whole custom admin-ui...
@AshokSapare-y2c
@AshokSapare-y2c Год назад
Hi Niko Kobler, can we use MongoDB as User Federation in Keycloak. Does User Storage SPI can be used for this purpose?
@dasniko
@dasniko Год назад
If you have watched the video, you should have seen that the SPI is being implemented in Java. So, if you can use Java to talk to a MongoDB (hint: yes, that‘s possible), then yes.
@AshokSapare-y2c
@AshokSapare-y2c Год назад
@@dasniko Thank you so much for your confirmation Niko 🙂. Somewhere I had doubt bcz document says LDAP, Active Directory and RDBMS it supports. Now it is clear.
@mehdiben9624
@mehdiben9624 2 года назад
Hi, can two clients in the same realm communicate with each other on keycloak ? if yes, how ? if no, why ?
@GlennPierce
@GlennPierce Год назад
Hi thanks just a couple of questions. If the peanuts service returned a jwt token that is used for future requests how does that get passed back to a client by keycloak ? Also am I correct in reading that a new mapping api has replace this now ? Do you still. Recommend using this api. Thanks againr
@dasniko
@dasniko Год назад
The peanuts service does not return a token, it's just for communication with a user store. The new store, based on a new "Map Storage SPI" is still in development and in "experimental" state. For production use, you have currently no alternative to the shown approach.
@GlennPierce
@GlennPierce Год назад
@@dasniko Thanks I know the peanuts service doesn't return ta token I meant if it did (like mine). I guess I could set the token as an attribute of the user and that would get exposed to clients.
@crossfirein2000
@crossfirein2000 2 года назад
Hi, Thanks for sharing this wonderful article. I have tested it in my local environment and it is working perfectly. Is it possible to add the additional information which is returned from the backend REST API to the generated token. And also let me know if it is possible to add custom response in case of authentication failure. Thanks...
@dasniko
@dasniko 2 года назад
1. yes 2. not ootb, this requires further customizations
@crossfirein2000
@crossfirein2000 2 года назад
@@dasniko Thanks.. Another thing I wanted to know that in the backend user names(most of the passwords also) are in upper case but keycloak is converting them to lower case resulting in the auth failure. Please suggest what could be the workaround. Thanks
@islembenarab5451
@islembenarab5451 Год назад
but i didnt find peanuts-user-provider in my choices when I lunched the server
@cuongnguyenminh6235
@cuongnguyenminh6235 2 года назад
Thank you so much
@ivandugandzic4014
@ivandugandzic4014 2 года назад
Hello Niko, is there option for remove Default configuration options for Unlink/Remove users from Local storage?
@dasniko
@dasniko 2 года назад
don't know
@audioqube6593
@audioqube6593 2 года назад
Hello Niko, i already realized a UserStorageProvider that access an external legacy Oracle Database for users with keycloak 16.1.1 but now with keycloak 17.0.0 I don't know how to tell my custom provider how to configure the additional datasource. Before the datasource was configured inside wildly but now? Please help me! I don't find anything in the documentation or forums that give me advices...Thank you in advance
@dasniko
@dasniko 2 года назад
The documentation, examples and also some adjustments in Keycloak core therefore will be available with version 18, I guess
@HosseinOjvar
@HosseinOjvar 2 года назад
Thanks man, You saved my day
@IgorSakaki
@IgorSakaki 2 года назад
Amazing video, very helpful!!! Do you know if possible match a client to a specific user federation?
@dasniko
@dasniko 2 года назад
This is not possible, because this makes no sense in context of an IdP
@Lamoboos223
@Lamoboos223 Год назад
make realm for each client .. this is a work around
@thed9299
@thed9299 2 года назад
Thanks for awesome tutorial and good explanation 👍 Is it possible if I use stand-alone Keyclock(on Docker) and then implement Custom User Storage Provider via spring-boot?
@dasniko
@dasniko 2 года назад
Providers have always to be implemented in Keycloak, not in an external ecosystem.
@YaroslavFedorov
@YaroslavFedorov 2 года назад
thank you!
@xpolr
@xpolr 2 года назад
Thanks for the video, but I get a strange bug on version 19.0.1: I compile your example, but I don't see provider settings except "Console display name", "Cache policy".
@xpolr
@xpolr 2 года назад
This error seems to occur only on version 19.0.1, after updating all fields are visible.
@dasniko
@dasniko 2 года назад
Yes, that‘s a bug in the new admin-UI, hopefully it‘s fixed completely. I recommend using the old admin-ui until KC 20, due to a lot of bugs all over.
@TaniaKampana
@TaniaKampana 2 месяца назад
Is it expected the users to have FederationLink?
@dasniko
@dasniko 2 месяца назад
Yes, of course. Otherwise Keycloak wouldn't know that theses users are originated in the respective provider.
@TaniaKampana
@TaniaKampana 2 месяца назад
@@dasniko The expected record in keycloak database is in the federated_user? When is it expected to be inserted in the record. In the ui seems to have the federated link, whereas when i am trying to get it from the UserModel, getFederatedLink is not in place. I am trying to understand where is the issue.
@ashishbajpayi4
@ashishbajpayi4 2 года назад
Hi, In my organization they have a requirement to have swagger functionality support for Keycloak. So for this, they want me to get the clone of it and make the changes to the source code. So, I want to ask is it required to get the clone and make the changes in the source code and build it? Will appreciate your early response Thanks.
@xpolr
@xpolr 2 года назад
You can simply modify your Swagger JSON by adding the necessary keycloak calls.
@sepact7999
@sepact7999 2 года назад
Hello Sir, thank you for the knowledge you provide for free. I'm new to Keycloak and i wanted to ask, if there is any way to deploy JAR-files, which contain javascript policies, into a Keycloak instance that is running from a docker container. I know that on my local machine, i can simply create a Jar that contains a keycloak-scripts.json file and the JavaScript policies, each policy being a single .js-file and then upload the jar pretty easily through the command line. However, I don't know how i could deploy them on a containerized instance.
@dasniko
@dasniko 2 года назад
You have to enable the "script-uploads" feature. See docs for details.
@paulcalinovici8808
@paulcalinovici8808 Год назад
I would like to extend Role mapping to add attributes like validTo, can you do a video about that, or can someone help me to find resources how to do that? Thx
@fadighattas9769
@fadighattas9769 2 года назад
thanks for the video, but how we can build and include the extension as jar file in keycloak docker container
@xpolr
@xpolr 2 года назад
Run the maven package, you will get a .jar file in build directory, which you should place in /opt/keycloak/providers (keycloak version >= 17.0.0)
@dasniko
@dasniko 2 года назад
Please see the official Keycloak server developer guide.
@abdurakhmonurazboev767
@abdurakhmonurazboev767 2 года назад
Hello Niko. Thank you for awesome video. I am currently playing around with Custom User Storage Provider. I have a Users microservice that I want to use as actual user storage provider, but I am having a difficulty to implement endpoints in that microservice for the SPI to make RestEasy requests to get required data and information. Could you please make additional video on this theme and show what will happen in the service itself that these Resteasy Requests are going to?
@abdurakhmonurazboev767
@abdurakhmonurazboev767 2 года назад
@@dasniko Sure, depending on how much it will be.
@abdurakhmonurazboev767
@abdurakhmonurazboev767 2 года назад
@@dasniko I see. I'm afraid that would be a bit expensive for me. What about hourly p2p mentoring? Do you offer such sessions?
@lts8683
@lts8683 2 года назад
Thank you I hope to make a video about User Storage SPI using database directly
@dasniko
@dasniko 2 года назад
There's an example available in the Keycloak quickstarts repository.
@juanmax832
@juanmax832 2 года назад
@@dasniko Please, can you paste a link? I can't find where. Thank you!
@raulperezguevara2966
@raulperezguevara2966 2 года назад
Thanks a loo, Niko, im having an issue trying to use an oracle external db as datasource on keycloak, but the oracle module is not loading, im using the lasted driver for oracle ojdb but i also tryed the previous one 11 and 8, im using oracle 19c and for keycloak version the 15.0.2, but i cant migrate it, this is the issue im having, failure description: "WFLYJCA0041: Failed to load module for driver [com.oracle]", hope someone in the comunity can help me, i know is not the correct place to ask.
@dasniko
@dasniko 2 года назад
Due to licencing, you have to care about the Oracle stuff yourself.
@rubenquiroz7315
@rubenquiroz7315 Год назад
Hello Nico, how can I customize only the user authentication, validate that the username and password in an external web service, authenticate it even if it is not registered in keycloak
@dasniko
@dasniko Год назад
That's exactly what the User Storage SPI is here for. Nothing else is doing my example.
@rubenquiroz7315
@rubenquiroz7315 Год назад
Thank you. So this is perfect for the use case where users need to be authenticated through an external web service without them being registered in keycloak?
@saguntumkar
@saguntumkar 2 года назад
Nice video. Can you please also add an example covering how can we add custom JPA entity provider in Keycloak Quarkus?
@dasniko
@dasniko 2 года назад
Look at the Keycloak quickstarts repository... there is an example of this.
@juroltv3119
@juroltv3119 2 года назад
Hello, where to deploy this? What directory should it be stored? I mean for the built jar file
@dasniko
@dasniko 2 года назад
Please see the official Keycloak server developer guide.
@Lamoboos223
@Lamoboos223 Год назад
/standalone/deployments
@dasniko
@dasniko Год назад
@@Lamoboos223 This is a bad answer as there is no context with it. Your answer is only valid for the legacy and now unsupported Wildfly version. That‘s why I point to the documentation, where it is mentioned depending on the version you are using.
@Lamoboos223
@Lamoboos223 Год назад
If you are using it powered by Quarkus then /providers folder should be the folder to deploy you ext with otherwise it is /standalone/deployments
@arturf7777
@arturf7777 2 года назад
great stuff
@satishchauhan9788
@satishchauhan9788 2 года назад
Hi Is there way to pass additional info to custom user storage provider ? I want to acess company id when creating new user...
@dasniko
@dasniko 2 года назад
You can pass anything you want into custom user attributes. Depends on your code and API where you get your data from.
@satishchauhan9788
@satishchauhan9788 2 года назад
@@dasniko thank you for reply, yes I have used attribute option to pass additional detail for user 👍
@juancuzmar7578
@juancuzmar7578 2 года назад
Thank you Niko for this amazing videos. I have a request if you don't mind. Can you talk about authorization services and add some example of it? It has been a bit difficult to understand and I think with an example and a use case it would be great. Thanks again!
@dasniko
@dasniko 2 года назад
No, sorry.
@juancuzmar7578
@juancuzmar7578 2 года назад
@@dasniko why don't you know how it works?
@dasniko
@dasniko 2 года назад
I know how it works, but I don't do videos about each and every topic and additionally, authZ services in Keycloak are - IMHO - badly/poorly implemented.
@juancuzmar7578
@juancuzmar7578 2 года назад
@@dasniko ooooh i see. thats rough
@ismailbouaziz3175
@ismailbouaziz3175 2 года назад
Hi, thank you for these awesome keycloak tutoria. Can u share your class diagram.
@dasniko
@dasniko 2 года назад
There is no class diagram. Should there be one? For 3-5 classes? Don't think so.
@ismailbouaziz3175
@ismailbouaziz3175 2 года назад
@@dasniko i have three classes users, roles and groups in my api I don't have a CredentialData class I have just a attribut password in class user what should do to adapt this solution to my api architecture!? thank you for your reply 🙏
@mcmdel
@mcmdel Год назад
Hi, Can you make a video about Key Cloak and API Six ?
@dasniko
@dasniko Год назад
no, sorry
@raghaveshukla7373
@raghaveshukla7373 Год назад
Hi Niko, Great Content Indeed. But can you showcase the same using Spring Boot
@dasniko
@dasniko Год назад
Why? Keycloak extensions can't be implemented using Spring.
@TestUser-wi5cn
@TestUser-wi5cn Год назад
Hello There. User Storage Provider has been deprecated. Do you have any work around for this?
@dasniko
@dasniko Год назад
It‘s not yet deprecated. It‘s the only one currently available.
@Lamoboos223
@Lamoboos223 Год назад
can it work on sql server database if I provided the jdbc url, username and password instead of the api?
@sirfinsaan
@sirfinsaan 2 года назад
superb video. I have one question? Is there any way to update User Personal Info like firstname lastname email etc ? keycloak 17 @Niko
@sirfinsaan
@sirfinsaan 2 года назад
I posted in the keycloak group as well :/ but still finding
@dasniko
@dasniko 2 года назад
You need to implement a proper user adapter (using some abstract classes as base or implement the pure UserModel interface)
@sirfinsaan
@sirfinsaan 2 года назад
@@dasniko Thank you, I did after implementing setAttribute but problem is that setAttribute wil take only one field as a update not more than one field when I submit... I will check more solutions
@annapetrosyan9195
@annapetrosyan9195 Год назад
Does someone have any update on this? I need to update username and email in my custom user storage from admin console ui.
Далее
1 Subscriber = 1 Penny
00:17
Просмотров 49 млн
Microservices with Databases can be challenging...
20:52
1 Subscriber = 1 Penny
00:17
Просмотров 49 млн