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

Order the response to the List an Identity's Sessions endpoint by authenticated_at/issued_at desc #295

Closed
6 tasks done
BrandonNoad opened this issue May 18, 2023 · 4 comments · Fixed by ory/kratos#3324
Closed
6 tasks done
Assignees
Labels
feat New feature or request.

Comments

@BrandonNoad
Copy link

Preflight checklist

Describe your problem

We need to cache the last login date for our users in our own db. So we've set up an after login webhook that sends the following payload: { identityId }.

The webhook handler fetches the identity associated with the identityId. This response, however, does not include the last login value. So, to be completely accurate, we should fetch all of the identity's sessions, find the most recent one, and store its authenticated_at date in our db. But an identity may have many pages of sessions, and they don't appear to be ordered in any particular way. So this task is not trivial. If the response was ordered by authenticated_at desc, then we could simply fetch a single page.

I suspect this endpoint's results not being ordered may have caused the following bug: #294. The UI may have decided to use only the active sessions because that would be a much smaller set, but it results in a bug when there are no active sessions.

On a related note, the "List All Sessions" endpoint should be ordered in a similar manner. Currently, the Sessions table in the Ory Network "Activity" tab is basically unusable since you can't sort or filter the results and there doesn't appear to be any ordering.

Describe your ideal solution

The response for the List an Identity's Sessions endpoint (GET https://{project}.projects.oryapis.com/admin/identities/{id}/sessions) should be ordered by authenticated_at descending.

Workarounds or alternatives

Fetch all the results and order them myself.

Version

Ory Network

Additional Context

No response

@BrandonNoad BrandonNoad added the feat New feature or request. label May 18, 2023
@kmherrmann
Copy link

Thanks for filing the issue - agree that we should order this way, and I'm adding this to our backlog.
@jonas-jonas FYI as this also affects the display in console

@jonas-jonas
Copy link
Member

Agreed, we should fix this. We have an API "spec" for flexible sorting/filtering in endpoints, it just needs to be implemented.

@jonas-jonas jonas-jonas self-assigned this Jun 13, 2023
@kmherrmann
Copy link

can we change the default order before adding explicit sort as a parameter?

@jonas-jonas
Copy link
Member

Should be possible, too. I'll have a look.

@hperl hperl assigned hperl and unassigned jonas-jonas Jun 19, 2023
hperl added a commit to ory/kratos that referenced this issue Jun 19, 2023
hperl added a commit to ory/kratos that referenced this issue Jun 19, 2023
aeneasr pushed a commit to ory/kratos that referenced this issue Jun 21, 2023
aeneasr pushed a commit to ory/kratos that referenced this issue Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants