2026-06-12

javascript to collect keycloak user list

but not sure which keycloak version.

---- 

$('.js-user-link').each(function() { console.log({ userId: $(this).data('user-id'), username: $(this).data('username'), fullName: $(this).find('.gl-avatar-labeled-label').text().trim(), email: $(this).find('.gl-avatar-labeled-sublabel').text().trim(), avatar: $(this).find('img').attr('src'), isAdmin: $(this).find('.badge').text().includes('Admin') }); });


here for version: 20.0.1

// 1. Safely get the current page indicator
const pageIndicator = document.querySelector(".pf-c-options-menu__toggle-text");
const currentPage = pageIndicator ? pageIndicator.textContent.trim() : "Unknown";

// 2. Initialize the array
const userDataList = [];

// 3. Select and iterate over rows
document.querySelectorAll('tr[data-ouia-component-type="PF4/TableRow"]').forEach(row => {
    const usernameCell = row.querySelector('td[data-label="Username"]');
    const emailCell = row.querySelector('td[data-label="Email"]');
    const lastNameCell = row.querySelector('td[data-label="Last name"]');
    const firstNameCell = row.querySelector('td[data-label="First name"]');

    // 4. Only push to list if all required cells exist
    if (usernameCell && emailCell && lastNameCell && firstNameCell) {
        userDataList.push({
            fromPage: currentPage,
            componentId: row.getAttribute('data-ouia-component-id'),
            username: usernameCell.textContent.trim(),
            email: emailCell.textContent.trim(),
            firstName: firstNameCell.textContent.trim(), // Kept separate
            lastName: lastNameCell.textContent.trim(),   // Kept separate
            profileUrl: usernameCell.querySelector('a')?.href || null
        });
    }
});

// 5. Log the result
if (userDataList.length > 0) {
    console.table(userDataList);
} else {
    console.warn("No complete user records found to display.");
}










No comments:

Post a Comment