Skip to content

Commit

Permalink
Support CheckPointPagination for fetching all clients
Browse files Browse the repository at this point in the history
  • Loading branch information
kailash-b committed Oct 30, 2024
1 parent cb62cbd commit 8b572e3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/Auth0.ManagementApi/Clients/ClientsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Auth0.ManagementApi.Clients
public class ClientsClient : BaseClient, IClientsClient
{
readonly JsonConverter[] converters = new JsonConverter[] { new PagedListConverter<Client>("clients") };
readonly JsonConverter[] checkpointConverters = new JsonConverter[] { new CheckpointPagedListConverter<Client>("clients") };

/// <summary>
/// Initializes a new instance of <see cref="ClientsClient"/>.
Expand Down Expand Up @@ -83,6 +84,33 @@ public Task<IPagedList<Client>> GetAllAsync(GetClientsRequest request, Paginatio

return Connection.GetAsync<IPagedList<Client>>(BuildUri("clients", queryStrings), DefaultHeaders, converters, cancellationToken);
}

/// <inheritdoc cref="IClientsClient.GetAllAsync(Auth0.ManagementApi.Models.GetClientsRequest,Auth0.ManagementApi.Paging.CheckpointPaginationInfo,System.Threading.CancellationToken)"/>
public Task<ICheckpointPagedList<Client>> GetAllAsync(GetClientsRequest request, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));

var queryStrings = new Dictionary<string, string>
{
{"fields", request.Fields},
{"include_fields", request.IncludeFields?.ToString().ToLower()},
{"is_global", request.IsGlobal?.ToString().ToLower()},
{"is_first_party", request.IsFirstParty?.ToString().ToLower()},
{"q", request.Query?.ToLower()}
};

if (pagination != null)
{
queryStrings["from"] = pagination.From?.ToString();
queryStrings["take"] = pagination.Take.ToString();
}

if (request.AppType != null)
queryStrings.Add("app_type", string.Join(",", request.AppType.Select(ExtensionMethods.ToEnumString)));

return Connection.GetAsync<ICheckpointPagedList<Client>>(BuildUri("clients", queryStrings), DefaultHeaders, checkpointConverters, cancellationToken);
}

/// <summary>
/// Retrieves a client by its id.
Expand Down
9 changes: 9 additions & 0 deletions src/Auth0.ManagementApi/Clients/IClientsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public interface IClientsClient
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{Client}"/> containing the clients.</returns>
Task<IPagedList<Client>> GetAllAsync(GetClientsRequest request, PaginationInfo pagination = null, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves a list of all client applications.
/// </summary>
/// <param name="request">Specifies criteria to use when querying clients.</param>
/// <param name="pagination">Specifies <see cref="CheckpointPaginationInfo"/> to use in requesting checkpoint-paginated results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="ICheckpointPagedList{Client}"/> containing the clients.</returns>
Task<ICheckpointPagedList<Client>> GetAllAsync(GetClientsRequest request, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves a client by its id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@ await fixture.ApiClient.Organizations.CreateClientGrantAsync(organization.Id,

var request = new GetClientsRequest()
{
Query = $"client_grant.organization_id:{organization.Id}"
Query = $"client_grant.allow_any_organization:true"
};

// Act
var clients = await fixture.ApiClient.Clients.GetAllAsync(request, new PaginationInfo(0, 100));
var clients = await fixture.ApiClient.Clients.GetAllAsync(request, new CheckpointPaginationInfo(100));

// Assert
Assert.Contains(clients.ToList(), x => x.ClientId == client.ClientId);
Expand Down

0 comments on commit 8b572e3

Please sign in to comment.