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

Add GET /sessions endpoint for retrieving all active sessions of authenticated user #228

Conversation

kacper-kicinski
Copy link

What type of PR is this?

  • feature

What this PR does / why we need it:

  • This PR adds a new GET /sessions endpoint for retrieving all active sessions of the authenticated user

Which issue(s) this PR fixes:

Fixes #101

Special notes for reviewers:

image

Changelog input

GET /sessions endpoint for retrieving all active sessions of authenticated user added.

@RandyLevensalor
Copy link
Collaborator

@kacper-kicinski The linters failed. Please check the results above and address. Thanks!

@kacper-kicinski
Copy link
Author

kacper-kicinski commented Oct 20, 2023

@kacper-kicinski The linters failed. Please check the results above and address. Thanks!

There is some issue that would be good to discuss here:

When a client requests for the list of active sessions, but there is no one, what HTTP code and response should be returned? We opt for returning just 200 and sessions = empty array. Another solution would be returning the 404 - Not Found, but we don't recommend it since it is not really an error, just the sessions list is empty.

But there is also another point: since we support pagination, the client could, in the request, specify a page value which is greater than the last available page (for example, there are pages 0,1,2 and the client requests for page 3, which does not exist). In that case, 404 could be returned. But here we go to the cause of linting failure - there is no Generic404 specification, which was referred here: https://github.com/kacper-kicinski/QualityOnDemand/blob/8f394bfa592e6aca23b9e952f959dbd842590d73/code/API_definitions/qod-api.yaml#L262

Possible solutions:

  1. Simply add Generic404 specification
  2. Change $ref from Generic404 to SessionNotFound404, which is already specified, but - does it really fit that case?
  3. Add PageNotFound404 specification and refer to it instead of Generic404
  4. Return in this case another response code, not 404 (but which one?)

For me, both 1 or 3 solutions could be applied. What do you think about it?

@rartych
Copy link
Contributor

rartych commented Oct 20, 2023

Summarizing our discussion during the call:

  • When there is no active session: return 200 and sessions = empty array
  • According to Design guidelines for page out of range the code 400 should be returned:
    400: request outside the range of the resource list
    It can cover:
    • Invalid pagination parameters (page or per_page less than 1)
    • Invalid page number (exceeding the total number of pages)

I think instead of

    Generic400:
      description: Invalid input

new response should be defined and used here:

    InvalidPagination400:
      description: Invalid pagination

What do you think?

@kacper-kicinski
Copy link
Author

kacper-kicinski commented Oct 23, 2023

@rartych thanks for the comment! Yes, I agree with the 400 code for invalid pagination.

Instead of creating a new error response template (like InvalidPagination400), I simply added two examples of the 400 response: PageOutOfRange and InvalidPerPageValue, directly in the GET /sessions specification because the pagination is only supported by this endpoint:

"400":
description: Invalid pagination for getSession operation
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorInfo"
examples:
PageOutOfRange:
summary: The page number is out of the range
value:
status: 400
code: INVALID_PAGINATION
message: "Invalid pagination: page number out of the range"
InvalidPerPageValue:
summary: The perPage value is less than 1
value:
status: 400
code: INVALID_PAGINATION
message: "Invalid pagination: perPage value can't be less than 1"

Do you agree with this solution, or should it be specified in another way?

@eric-murray
Copy link
Collaborator

Please see my comment in the associated issue

@eric-murray eric-murray marked this pull request as draft October 23, 2023 10:43
@akoshunyadi
Copy link
Collaborator

Returning only the sessionIds would make filters even more useful. E.g. for MSISDN

Copy link
Collaborator

@jlurien jlurien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The topic of sessions ownership and requirements for implementations to check access tokens is now critical with the new endpoint, but it is probably something that we may need for previous GET /session/{sessionId} as well. We assumed sessionId was a "secret", but it makes sense to validate also that the sessionId was created by the client_id and for for the user linked to the access token.

sessions:
description: Array of sessions to be returned.
type: array
items:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
items:
minItems: 0
items:

@@ -433,6 +493,23 @@ components:
- expiresAt
- qosStatus

SessionInfoList:
description: Paged response of active sessions created by the user
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we mention created by the user, and above created by the client. This topic is very relevant for this endpoint as discussed in #101. The logic must be to return the sessions that are allowed to be discovered by the access token. In the most restrictive case, for three-legged tokens, that includes checking both client_id and user.
Returning just sessionIds or all session details does not change the picture, if knowing sessionIds is enough to get session details in a separate operation.

tags:
- QoS sessions
summary: Get all active sessions information
description: Get information about all active sessions that were created by the client
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we should indicate that the returned sessions will be those allowed to be discovered with the provided access token, which will depend on the type of access token provided, 2-legged or 3-legged. This has to be clarified in the implementation guidelines and aligned with Identity&Consent Management guidelines, but to progress with the spec we could add something like:

Suggested change
description: Get information about all active sessions that were created by the client
description: Get information about all active sessions authorized to be retrieved by the provided access token.

summary: Get all active sessions information
description: Get information about all active sessions that were created by the client
operationId: getSessions
parameters:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be interesting to add additional filters, specially to allow filtering sessions for some specific device

@@ -433,6 +493,23 @@ components:
- expiresAt
- qosStatus

SessionInfoList:
description: Paged response of active sessions created by the user
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: Paged response of active sessions created by the user
description: Paged response of active sessions authorized to be retrieved by the provided access token.

description: Get information about all active sessions that were created by the client
operationId: getSessions
parameters:
- name: perPage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paging could be interesting for 2-legged scenarios where some client_id may potentially create lots of sessions. For 3-legged scenarios, paging is probably not that necessary, as each user will likely have a limited number of active sessions. Until we fully clarify which kind of tokens will be allowed for QoD, I would not add paging parameters yet, we could add them in a subsequent review if they are needed.

@kacper-kicinski
Copy link
Author

Thank you for the comments. I removed pagination, changed some descriptions, allowed filtering of sessions by phoneNumber. For now I left the response as a list of whole sessions. However, we can continue to discuss wheter it would be better to return only sessionsIds.

required: false
description: Allows filtering of sessions by device (phone number).
schema:
$ref: "#/components/schemas/PhoneNumber"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add two more spaces to resolve linting issue.

@hdamker
Copy link
Collaborator

hdamker commented Nov 17, 2023

@kacper-kicinski Would you mind to declare the PR "ready for review"?

We discussed in today's QoD meeting that the PR will make it into the v0.10.0 release candidate only if it can be finished (= including final reviews and approvals) together with the other three open PRs within the next week (until Friday Nov 24th). The goal is to create the release candidate at the end of next week. If the PR will be not ready to be merged until then it will not make it into v0.10.0.

description: Get information about all active sessions authorized to be retrieved by the provided access token.
operationId: getSessions
parameters:
- name: phoneNumber
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to filter on $ref: "#/components/schemas/Device and not just phone number.

@RandyLevensalor
Copy link
Collaborator

Returning only the sessionIds would make filters even more useful. E.g. for MSISDN

Only returning sessionIds could be a much faster and more responsive API call than returning the complete session object. Especially with filtering, where the sessionId may be sufficient. Plus, there is an existing API call to get the session information based on sessionId.

@hdamker
Copy link
Collaborator

hdamker commented Nov 20, 2023

Please see my comment within the issue where I summarized the open discussions based on our QoD call on Friday.

From that it is yet to be decided for v0.10.0

  • Paging or not
  • Filtering on phoneNumber only vs filtering on device object (comment above)

Co-authored-by: Randy Levensalor <randymartini@gmail.com>
@kacper-kicinski kacper-kicinski marked this pull request as ready for review November 21, 2023 08:02
@jlurien
Copy link
Collaborator

jlurien commented Nov 22, 2023

I changed the response from a list of whole session objects to a list of only session IDs. Please read Herbert's comment. There are some open points for further discussion, pagination, security, filtering etc. MR is now ready for review. Kindly ask reviewers to take a look.

This is not aligned with the decision we took during last meeting:

Should the operation deliver the full session information or just the session ids?
Result of the discussion: return the full session information
Rational: this is the more developer friendly option, as otherwise the API consumer would need to call getSession one by one to find the information they are looking for. From privacy perspective has the API consumer provided and seen all personal information already during the respective session creations. It should be enough that the API consumer was authorized to create the sessionId(s) to assume consent for the get operation.

@kacper-kicinski
Copy link
Author

I reverted commit about changing the response from whole session objects to only sessionIds. It was a mistake. As Herbert wrote in his comment - "Result of the discussion: return the full session information"

@hdamker
Copy link
Collaborator

hdamker commented Nov 27, 2023

Setting the PR again to "draft" as the discussions within #101 are not yet concluded and still active.

@eric-murray
Copy link
Collaborator

Issue #101 is now active again, and I think @patrice-conil and myself have landed on a proposal that we both can live with. Can others review and comment?

The main difference is that the new endpoint will only return session details that were created by the API consumer for a given end user device. The end user device will be identified from the OAuth token, so will not need to be explicitly specified in the API definition.

For those that don't understand how this will work, see here.

@jlurien
Copy link
Collaborator

jlurien commented Jan 24, 2024

Issue #101 is now active again, and I think @patrice-conil and myself have landed on a proposal that we both can live with. Can others review and comment?

The main difference is that the new endpoint will only return session details that were created by the API consumer for a given end user device. The end user device will be identified from the OAuth token, so will not need to be explicitly specified in the API definition.

For those that don't understand how this will work, see here.

I have replied as well in the other issue thread, and I have drafted a proposal to change this operation to a POST method, that would ease many problems that we face with the GET. Regarding whether the device has to be provided explicitly or may be identified by the token, I think that this question is not specific to the new operation. For createSession, we should have the same requirements regarding security, in order to check that the access token allows the client to create session for certain device, and in some cases the device could be known from the access token directly, so we could make device optional for createSession as well.

@hdamker
Copy link
Collaborator

hdamker commented Aug 1, 2024

This stale PR is superseded by #325.

@hdamker hdamker closed this Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

List endpoint for active sessions of authenticated user
8 participants