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

Broken pagination using page_token in Ory Hydra APIs #3362

Closed
4 of 6 tasks
Urbansson opened this issue Nov 14, 2022 · 6 comments · Fixed by #3384
Closed
4 of 6 tasks

Broken pagination using page_token in Ory Hydra APIs #3362

Urbansson opened this issue Nov 14, 2022 · 6 comments · Fixed by #3384
Labels
bug Something is not working.

Comments

@Urbansson
Copy link

Urbansson commented Nov 14, 2022

Preflight checklist

Describe the bug

When paginating over the oauth2 clients using the /admin/clients endpoint the the result returned jumps over multiple clients.

Reproducing the bug

Make a request to /admin/clients?page_size=3
The expected result is to have 3 clients returned and a link header containing
</admin/clients?page_size=3&page_token=eyJwYWdlIjoiMyIsInYiOjF9>; rel="next"

Make a request using the next Link returned int the header /admin/clients?page_size=3&page_token=eyJwYWdlIjoiMyIsInYiOjF9
Here we expect to get the following 3 clients. But instead it jumps multiple clients.

You can spot this by comparing the result from a request to /admin/clients?page_size=300

Relevant log output

No response

Relevant configuration

serve:
  cookies:
    same_site_mode: Lax

urls:
  self:
    issuer: http://127.0.0.1:4444
  consent: http://127.0.0.1:3000/consent
  login: http://127.0.0.1:3000/login
  logout: http://127.0.0.1:3000/logout
  error: http://127.0.0.1:3000/error

secrets:
  system:
    - youReallyNeedToChangeThis

webfinger:
  oidc_discovery:
    supported_claims:
      - email
      - email_verified
      - name
      - family_name
      - given_name
      - picture
      - updated_at
    supported_scope:
      - offline
      - openid
      - profile
      - userinfo.profile
      - email
      - userinfo.email
      
    userinfo_url: http://127.0.0.1:3000/api/userinfo

oidc:
  subject_identifiers:
    supported_types:
      - pairwise
      - public
    pairwise:
      salt: youReallyNeedToChangeThis

log:
  level: debug
  format: text
  leak_sensitive_values: true

Version

2.0.2

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Docker

Additional Context

If we take a deeper look into the token returned from the /admin/clients?page_size=3 request we see that it contains: {"page":"3","v":1}.

If it was the page return we should expect to get the value 1 and not 3, it instead looks like we are getting a offset to the next page.

But If we look when parsing the token in the request using the token we see the following:

hydra/client/handler.go

Lines 507 to 514 in c65342e

func (h *Handler) listOAuth2Clients(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
page, itemsPerPage := x.ParsePagination(r)
filters := Filter{
Limit: itemsPerPage,
Offset: page * itemsPerPage,
Name: r.URL.Query().Get("client_name"),
Owner: r.URL.Query().Get("owner"),
}

Here we still handle it as a page and not a offset getting the values page=3 and itemsPerPage=3 ParsePagination and then calculating a offset Offset: page * itemsPerPag ending up as 9. This means we are jumping over the clients with index 3-9 when paging.

So we are mixing offset and page based pagination. Which is the way we want to do stuff?

I would probably prefer changing the page_token content from {"page":"3","v":1} to {"offset":"3","v":1} to keep the token independent from the page_size query param.

@Urbansson Urbansson added the bug Something is not working. label Nov 14, 2022
@aeneasr
Copy link
Member

aeneasr commented Nov 16, 2022

Thank you for the report! Adding this to our backlog.

@aeneasr aeneasr changed the title Broken pagination using page_token. Broken pagination using page_token in Ory Hydra APIs Nov 16, 2022
@aeneasr
Copy link
Member

aeneasr commented Nov 16, 2022

ps: contributions also welcomed, we will probably not be able to work on this in the next weeks

@Urbansson
Copy link
Author

I'm happy to help with this issue, would you prefer storing the offset or a page index in the page_token?

@aeneasr
Copy link
Member

aeneasr commented Nov 21, 2022

The page index would be nicer to store in the page_token! but offset is also fine - whatever is easier :)

@bulolo
Copy link

bulolo commented Nov 28, 2022

how can i know my current page?

image

example:
i want to have currentPage
image

@Urbansson
Copy link
Author

Urbansson commented Nov 28, 2022

I would say you can't do it.
Usually when paginating with cursors/tokens you probably want to go for a infinite scroll solution so you just load more as it is requested.

aeneasr added a commit to ory/x that referenced this issue Nov 28, 2022
aeneasr added a commit to ory/x that referenced this issue Nov 28, 2022
aeneasr added a commit that referenced this issue Dec 7, 2022
@aeneasr aeneasr mentioned this issue Dec 7, 2022
7 tasks
aeneasr added a commit that referenced this issue Dec 7, 2022
aeneasr added a commit that referenced this issue Dec 8, 2022
aeneasr added a commit that referenced this issue Dec 8, 2022
harnash pushed a commit to Wikia/ory-hydra that referenced this issue Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants