I try to get a user by it’s id in a custom keycloak extension. When I try the session.users().getUsersById(userId, realm) it returns null, BUT in the same method session.users().getUsers(realm) contains the user (with the correct id) that I need.
I am using keycloak 11.0.3. For the extension I use/extend the RealmResourceProvider/Factory to provide an API endpoint. I always hand over the session in the constructor from the factory through the provider to the actual component that contains the business logic. The realm I use for the above calls is not master. I provide it using session.realms().getRealm(realmId);
Current workaround is to loop through the realm’s users (from session.users().getUsers(realm)) and “manually” filter on equal userId. But this is not working well for large user bases, so I cannot keep it.
Any ideas what I am doing wrong or other suggestions are welcome!