Skip to content

[FEATURE] Add ListMembersAsync to IKcOrganizations #25

@sugarst

Description

@sugarst

Interface extension

  • file path : NETCore.Keycloak.Client/HttpClients/Abstraction/IKcOrganizations.cs
/// <summary>
/// Retrieves the members of a specific organization in a Keycloak realm with pagination support.
///
/// GET /{realm}/organizations/{organizationId}/members?first={first}&max={max}
/// </summary>
/// <param name="realm">The Keycloak realm in which the organization resides.</param>
/// <param name="accessToken">The access token used for authentication.</param>
/// <param name="organizationId">The unique identifier of the organization.</param>
/// <param name="filter">Optional filter with pagination (First, Max) and BriefRepresentation.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns>
/// A <see cref="KcResponse{T}"/> containing a list of <see cref="KcUser"/> objects
/// representing the organization's members.
/// </returns>
/// <exception cref="KcException">Thrown if any required parameter is null or invalid.</exception>
Task<KcResponse<IEnumerable<KcUser>>> ListMembersAsync(
    string realm,
    string accessToken,
    string organizationId,
    KcFilter filter = null,
    CancellationToken cancellationToken = default);

Implement Expansion

  • file path : NETCore.Keycloak.Client/HttpClients/Implementation/KcOrganizations.cs
/// <inheritdoc cref="IKcOrganizations.ListMembersAsync"/>
public Task<KcResponse<IEnumerable<KcUser>>> ListMembersAsync(
    string realm,
    string accessToken,
    string organizationId,
    KcFilter filter = null,
    CancellationToken cancellationToken = default)
{
    ValidateAccess(realm, accessToken);
    ValidateRequiredString(nameof(organizationId), organizationId);
    filter ??= new KcFilter();

    var url = $"{BaseUrl}/{realm}/organizations/{organizationId}/members{filter.BuildQuery()}";
    return ProcessRequestAsync<IEnumerable<KcUser>>(
        url,
        HttpMethod.Get,
        accessToken,
        "Unable to list organization members",
        cancellationToken: cancellationToken);
}

Design Notes:

  • Use basic KcFilter (including First/Max/Brief Representation) as the paging parameter and match it with the Keyclone 26.2 Organization Members API parameter
  • Return IEnumerable, reuse the existing KcUser model, and return the same type as IKcGroups. GetMembers Sync
  • URL mode: GET/admin/hearts/{reality}/organizations/{organizationId}/members? first=0&max=300

New using references need to be added

// IKcOrganizations.cs 顶部新增
using NETCore.Keycloak.Client.Models.Users;
using NETCore.Keycloak.Client.Models.Common;

// KcOrganizations.cs 顶部新增
using NETCore.Keycloak.Client.Models.Users;
using NETCore.Keycloak.Client.Models.Common;

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions