diff --git a/src/Auth0.ManagementApi/Clients/IOrganizationsClient.cs b/src/Auth0.ManagementApi/Clients/IOrganizationsClient.cs index c4f72b2c3..10013babb 100644 --- a/src/Auth0.ManagementApi/Clients/IOrganizationsClient.cs +++ b/src/Auth0.ManagementApi/Clients/IOrganizationsClient.cs @@ -128,6 +128,16 @@ public interface IOrganizationsClient /// An containing the organization members. Task> GetAllMembersAsync(string organizationId, PaginationInfo pagination, CancellationToken cancellationToken = default); + /// + /// Retrieves a list of all organization members. + /// + /// The ID of the organization for which you want to retrieve the members. + /// Specifies criteria to use when querying organization members. + /// Specifies pagination info to use when requesting paged results. + /// The cancellation token to cancel operation. + /// An containing the organization members. + Task> GetAllMembersAsync(string organizationId, OrganizationGetAllMembersRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default); + /// /// Retrieves a list of all organization members using checkpoint . /// @@ -137,6 +147,16 @@ public interface IOrganizationsClient /// An containing the organization members. Task> GetAllMembersAsync(string organizationId, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default); + /// + /// Retrieves a list of all organization members using checkpoint . + /// + /// The ID of the organization for which you want to retrieve the members. + /// Specifies criteria to use when querying organization members. + /// Specifies to use in requesting checkpoint-paginated results. + /// The cancellation token to cancel operation. + /// An containing the organization members. + Task> GetAllMembersAsync(string organizationId, OrganizationGetAllMembersRequest request, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default); + /// /// Deletes members from an organization. /// diff --git a/src/Auth0.ManagementApi/Clients/OrganizationsClient.cs b/src/Auth0.ManagementApi/Clients/OrganizationsClient.cs index 42c03683f..098dd1fd3 100644 --- a/src/Auth0.ManagementApi/Clients/OrganizationsClient.cs +++ b/src/Auth0.ManagementApi/Clients/OrganizationsClient.cs @@ -218,6 +218,19 @@ public Task AddMembersAsync(string organizationId, OrganizationAddMembersRequest /// The cancellation token to cancel operation. /// An containing the organization members. public Task> GetAllMembersAsync(string organizationId, PaginationInfo pagination, CancellationToken cancellationToken = default) + { + return GetAllMembersAsync(organizationId, null, pagination, cancellationToken); + } + + /// + /// Retrieves a list of all organization members. + /// + /// The ID of the organization for which you want to retrieve the members. + /// Specifies criteria to use when querying organization members. + /// Specifies pagination info to use when requesting paged results. + /// The cancellation token to cancel operation. + /// An containing the organization members. + public Task> GetAllMembersAsync(string organizationId, OrganizationGetAllMembersRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default) { if (pagination == null) throw new ArgumentNullException(nameof(pagination)); @@ -229,6 +242,12 @@ public Task> GetAllMembersAsync(string organizati {"include_totals", pagination.IncludeTotals.ToString().ToLower()}, }; + if (request != null) + { + queryStrings.Add("fields", request.Fields); + queryStrings.Add("include_fields", request.IncludeFields?.ToString().ToLower()); + } + return Connection.GetAsync>(BuildUri($"organizations/{EncodePath(organizationId)}/members", queryStrings), DefaultHeaders, membersConverters, cancellationToken); } @@ -240,6 +259,19 @@ public Task> GetAllMembersAsync(string organizati /// The cancellation token to cancel operation. /// An containing the organization members. public Task> GetAllMembersAsync(string organizationId, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default) + { + return GetAllMembersAsync(organizationId, null, pagination, cancellationToken); + } + + /// + /// Retrieves a list of all organization members using checkpoint . + /// + /// The ID of the organization for which you want to retrieve the members. + /// Specifies criteria to use when querying organization members. + /// Specifies to use in requesting checkpoint-paginated results. + /// The cancellation token to cancel operation. + /// An containing the organization members. + public Task> GetAllMembersAsync(string organizationId, OrganizationGetAllMembersRequest request, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default) { if (pagination == null) throw new ArgumentNullException(nameof(pagination)); @@ -250,6 +282,12 @@ public Task> GetAllMembersAsync(string {"take", pagination.Take.ToString()}, }; + if (request != null) + { + queryStrings.Add("fields", request.Fields); + queryStrings.Add("include_fields", request.IncludeFields?.ToString().ToLower()); + } + return Connection.GetAsync>(BuildUri($"organizations/{EncodePath(organizationId)}/members", queryStrings), DefaultHeaders, membersCheckpointConverters, cancellationToken); } diff --git a/src/Auth0.ManagementApi/Models/OrganizationGetAllMembersRequest.cs b/src/Auth0.ManagementApi/Models/OrganizationGetAllMembersRequest.cs new file mode 100644 index 000000000..711f5cdd6 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/OrganizationGetAllMembersRequest.cs @@ -0,0 +1,15 @@ +namespace Auth0.ManagementApi.Models +{ + public class OrganizationGetAllMembersRequest { + + /// + /// A comma separated list of fields to include or exclude (depending on ) from the result, empty to retrieve all fields. + /// + public string Fields { get; set; } = null; + + /// + /// Specifies whether the fields specified in should be included or excluded in the result. + /// + public bool? IncludeFields { get; set; } = null; + } +} \ No newline at end of file diff --git a/tests/Auth0.ManagementApi.IntegrationTests/OrganizationTests.cs b/tests/Auth0.ManagementApi.IntegrationTests/OrganizationTests.cs index 6b4618dd9..a15f91c18 100644 --- a/tests/Auth0.ManagementApi.IntegrationTests/OrganizationTests.cs +++ b/tests/Auth0.ManagementApi.IntegrationTests/OrganizationTests.cs @@ -219,9 +219,11 @@ public async Task Test_organization_members_crud_sequence() try { - var members = await RetryUtils.Retry(() => fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new Paging.PaginationInfo()), members => members.Count != 2); + var members = await RetryUtils.Retry(() => fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new OrganizationGetAllMembersRequest { Fields = "name", IncludeFields = false }, new Paging.PaginationInfo()), members => members.Count != 2); members.Count.Should().Be(2); + members[0].Name.Should().BeNull(); + members[1].Name.Should().BeNull(); await fixture.ApiClient.Organizations.DeleteMemberAsync(ExistingOrganizationId, new OrganizationDeleteMembersRequest { @@ -275,10 +277,12 @@ public async Task Test_organization_members_checkpoint_pagination() await RetryUtils.Retry(() => fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new Paging.CheckpointPaginationInfo(2)), response => response.Count != 2); - var firstCheckPointPaginationRequest = await fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new Paging.CheckpointPaginationInfo(1)); + var firstCheckPointPaginationRequest = await fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new OrganizationGetAllMembersRequest { Fields = "name", IncludeFields = false }, new Paging.CheckpointPaginationInfo(1)); var secondCheckPointPaginationRequest = await fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new Paging.CheckpointPaginationInfo(1, firstCheckPointPaginationRequest.Paging.Next)); + firstCheckPointPaginationRequest[0].Name.Should().BeNull(); secondCheckPointPaginationRequest.Count.Should().Be(1); + secondCheckPointPaginationRequest[0].Name.Should().NotBeNull(); secondCheckPointPaginationRequest.Paging.Next.Should().NotBeNullOrEmpty(); }