ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
137 stars 85 forks source link

[Kratos] listIdentities Endpoint don't work as expected #284

Closed RocKordier closed 10 months ago

RocKordier commented 1 year ago

Preflight checklist

Describe the bug

ATM its not possible to fetch the first page of the listIdentities Endpoint.

Ory admin console doing it the right way, I think.

Screenshot 2023-07-16 at 15 58 16

The page parameter should also allow page 0.

Also I'm a bit confused about the Endpoint description. https://www.ory.sh/docs/kratos/reference/api#tag/identity/operation/listIdentities

This value is currently an integer, but it is not sequential. The value is not the page number, but a reference. The next page can be any number and some numbers might return an empty list.

For example, page 2 might not follow after page 1. And even if page 3 and 5 exist, but page 4 might not exist.

Why the page - parameter isn't a real page parameter? Whats the recommended way to safely fetch all identities via API? Why there could be empty pages in between? Is it intended to look at the x-total-count - Header and fetch pages as long as all identities has been fetched? How does the ory admin console calculate the page selector?

Thx for your help Eric

Reproducing the bug

STR:

  1. Install one of the provided API Clients
  2. Instantiate the IdentityApi Client
  3. Try to fetch page 0
    
    <?php
    require_once './vendor/autoload.php';

$config = new \Ory\Kratos\Client\Configuration(); $config->setHost('https://host.tld'); $config->setApiKey('Authorization', 'Bearer ory_pat_xxx');

$api = new \Ory\Kratos\Client\Api\IdentityApi(new \GuzzleHttp\Client(), $config);

[$identities, $error, $headers] = $api->listIdentitiesWithHttpInfo(20, 0);


### Relevant log output

```shell
PHP Fatal error:  Uncaught InvalidArgumentException: invalid value for "$page" when calling IdentityApi.listIdentities, must be bigger than or equal to 1. in ~/project/vendor/ory/kratos-client-php/lib/Api/IdentityApi.php:4068

Relevant configuration

-

Version

ory/kratos-client-php:0.13.1

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Ory Network

Additional Context

No response

jletroui commented 11 months ago

Definitely an issue. The HTTP API clearly supports page 0, when trying with the CLI. Example ( with Kratos 1.0.0):

> kratos list identities 0 10
2023/08/30 16:48:59 [DEBUG] GET http://kratos_bdshifters_svc:4434/admin/identities?page=0&per_page=10
ID                                      VERIFIED ADDRESSES                      RECOVERY ADDRESSES                      SCHEMA ID       SCHEMA URL
71bd916d-cabf-453e-aedf-4a438da9c9c4    j@gmail.com                             j@gmail.com                             default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
708b637b-29d2-4113-b51f-b6e4fa5e0dd9    verif6@gmail.com                        verif6@gmail.com                        default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
695a4564-4d8f-4555-9b21-f381e62a8231    ju3@gmail.com                           ju3@gmail.com                           default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
5a474bf8-dd3c-4894-bcfa-d417bd1dadd5    ju@gmail.com                            ju@gmail.com                            default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
523c2198-e5f7-4252-bea1-53ad7d20dca2    ju4@gmail.com                           ju4@gmail.com                           default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
5169f4d2-ca24-4876-9b23-7acbac71d531    verif10@gmail.com                       verif10@gmail.com                       default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
508fb41e-236b-471c-ae07-60336241f616    julien.r@gmail.com                      julien.r@gmail.com                      default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
46149db0-157d-4c38-a2c2-ae2b082b51ec    ju5@gmail.com                           ju5@gmail.com                           default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
0f3fdd01-229f-43a0-b27c-929431b086a4    test_upsert_orders.x0976jdh@mail.com    test_upsert_orders.x0976jdh@mail.com    default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg
0ab1e51d-d51b-471b-87dc-e5f278f8d475    verif2@gmail.com                        verif2@gmail.com                        default_v2      http://localhost:4200/proxy/kratos/schemas/ZGVmYXVsdF92Mg

This makes the use of the SDK useless, since we can't fetch the complete list of identities.

aeneasr commented 11 months ago

It looks like the SDK definition is not correct here. page and per_page are actually deprecated, and one should use page_token and page_size instead.