How does the background inner working of the UserStorageProvider works?

Hi. I am developing a UserStorageProvider implementation so that I can get my KeyCloak users from a external DB. I would like to know a little bit better how this works on the background. For example, when retrieving the users, I can see that KeyCloak first tries to get them by username and then by Id.

Also, I see that the Id it searches for the storage Ids, which have the componentModel ID appended to them.

But what does that mean to my implementation? My Ids should look like something specific? Should I trim the query to search only by the part that references my externalID?

If I get f:332a234e31234:wburke as the parameter in my getById() should I trim this to look in my DB only for wburke? Also, my Id is not a username, is a uID, so why does it give me a username?

It looks like since the docs state:

The provider again parses the id to obtain the external id and it will use to locate the user in external user storage.

I am a little bit lost and I cannot find such information in the documentation. Can someone explain me the inner works and what am I supposed to do? I would greatly appreciate it.

Thanks in advance.

It might help to look at an example extension that’s similar to what you’re trying to do.

This is one that allows the Keycloak users to be stored in an external database, and you can configure the connection and queries used.

1 Like