Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetAllInvitationsAsync pagination length returns zero #779

Open
5 tasks done
luch0-dev opened this issue Feb 6, 2025 · 2 comments
Open
5 tasks done

GetAllInvitationsAsync pagination length returns zero #779

luch0-dev opened this issue Feb 6, 2025 · 2 comments
Assignees
Labels
bug This points to a verified bug in the code

Comments

@luch0-dev
Copy link

luch0-dev commented Feb 6, 2025

Checklist

  • I have looked into the Readme and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

GetAllInvitationsAsync always returns zero for length, issue appears be a result of /src/Auth0.ManagementApi/Paging/PagedListConverter.cs when only limit is present (as with management API endpoint https://{tenant}/api/v2/organizations/{org_id}/invitations?include_totals=true), the page size is incorrectly set to 0.

Reproduction

Sample showing discrepancy of SDK vs management API

using Auth0.ManagementApi;
using Auth0.ManagementApi.Models;
using Auth0.ManagementApi.Paging;
using Microsoft.Extensions.Configuration;
using System.Text.Json;

class Program
{
    static async Task Main()
    {
        var config = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .Build();

        var token = await GetToken(config);
        var client = new ManagementApiClient(token, new Uri($"https://{config["Auth0:Domain"]}/api/v2"));

        var organizationId = config["Auth0:OrganizationId"];
        var pagination = new PaginationInfo(0, 50, true);
        var request = new OrganizationGetAllInvitationsRequest();

        var httpClient = new HttpClient();
        httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
        var rawResponse = await httpClient.GetAsync(
            $"https://{config["Auth0:Domain"]}/api/v2/organizations/{organizationId}/invitations?page=0&per_page=50&include_totals=true");

        Console.WriteLine("Raw API Response:");
        Console.WriteLine(await rawResponse.Content.ReadAsStringAsync());

        var invitations = await client.Organizations.GetAllInvitationsAsync(organizationId, request, pagination);
        
        Console.WriteLine("\nSDK Parsed Results:");
        if (invitations is IPagedList<OrganizationInvitation> pagedList)
        {
            Console.WriteLine($"Start: {pagedList.Paging?.Start}");
            Console.WriteLine($"Length: {pagedList.Paging?.Length}");
            Console.WriteLine($"Items Count: {invitations.Count()}");
        }
    }

    static async Task<string> GetToken(IConfiguration config)
    {
        var tokenRequest = new
        {
            client_id = config["Auth0:ClientId"],
            client_secret = config["Auth0:ClientSecret"],
            audience = $"https://{config["Auth0:Domain"]}/api/v2/",
            grant_type = "client_credentials"
        };

        var httpClient = new HttpClient();
        var response = await httpClient.PostAsync(
            $"https://{config["Auth0:Domain"]}/oauth/token",
            new StringContent(JsonSerializer.Serialize(tokenRequest), System.Text.Encoding.UTF8, "application/json"));

        var tokenResponse = await response.Content.ReadAsStringAsync();
        return JsonDocument.Parse(tokenResponse).RootElement.GetProperty("access_token").GetString();
    }
}

Additional context

No response

auth0.net version

7.330

.NET version

8.0.405

@luch0-dev luch0-dev added the bug This points to a verified bug in the code label Feb 6, 2025
@kailash-b kailash-b self-assigned this Feb 6, 2025
@kailash-b
Copy link
Contributor

Thanks for bringing this to our notice @luch0-dev
We will analyse this.

@kailash-b
Copy link
Contributor

Hi @luch0-dev
Seems the response has just the start and limit values and that's the reason the rest of the values default to 0.
Also in the documentation there is another call-out as follows We do not yet support returning the total invitations count. from the API.
Let us know if this clarifies your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

No branches or pull requests

2 participants