Skip to content

Commit

Permalink
refactor(consent): rename SDK method from `adminListSubjectConsentSes…
Browse files Browse the repository at this point in the history
…sions` to `adminListOAuth2SubjectConsentSessions`

BREAKING CHANGE: Rename SDK method from `adminListSubjectConsentSessions` to `adminListOAuth2SubjectConsentSessions`.
  • Loading branch information
aeneasr committed Sep 7, 2022
1 parent 1108409 commit bb51ba0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
6 changes: 4 additions & 2 deletions client/handler.go
Expand Up @@ -482,8 +482,10 @@ type adminListOAuth2Clients struct {
// OAuth 2.0 clients are used to perform OAuth 2.0 and OpenID Connect flows. Usually, OAuth 2.0 clients are
// generated for applications which want to consume your OAuth 2.0 or OpenID Connect capabilities.
//
// The "Link" header is also included in successful responses, which contains one or more links for pagination, formatted like so: '<https://hydra-url/admin/clients?limit={limit}&offset={offset}>; rel="{page}"', where page is one of the following applicable pages: 'first', 'next', 'last', and 'previous'.
// Multiple links can be included in this header, and will be separated by a comma.
// The "Link" header is also included in successful responses, which contains one or more links for pagination,
// formatted like so: '<https://project-slug.projects.oryapis.com/admin/clients?limit={limit}&offset={offset}>; rel="{page}"',
// where page is one of the following applicable pages: 'first', 'next', 'last', and 'previous'. Multiple links can
// be included in this header, and will be separated by a comma.
//
// Consumes:
// - application/json
Expand Down
15 changes: 0 additions & 15 deletions consent/doc.go
Expand Up @@ -43,21 +43,6 @@ type swaggerGetLogoutRequestByChallenge struct {
Challenge string `json:"logout_challenge"`
}

// swagger:parameters listSubjectConsentSessions
type swaggerListSubjectConsentSessionsPayload struct {
// in: query
// required: true
Subject string `json:"subject"`

// The maximum amount of consent sessions to be returned, upper bound is 500 sessions.
// in: query
Limit int `json:"limit"`

// The offset from where to start looking.
// in: query
Offset int `json:"offset"`
}

// swagger:parameters revokeAuthenticationSession
type swaggerRevokeAuthenticationSessionPayload struct {
// in: query
Expand Down
27 changes: 17 additions & 10 deletions consent/handler.go
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/ory/hydra/driver/config"
"github.com/ory/hydra/x"
"github.com/ory/x/errorsx"
"github.com/ory/x/pagination"
"github.com/ory/x/sqlxx"
"github.com/ory/x/stringsx"
"github.com/ory/x/urlx"
Expand Down Expand Up @@ -100,7 +99,7 @@ type adminRevokeOAuth2ConsentSessions struct {
All bool `json:"all"`
}

// swagger:route DELETE /admin/oauth2/auth/sessions/consent admin revokeConsentSessions
// swagger:route DELETE /admin/oauth2/auth/sessions/consent v1 adminRevokeOAuth2ConsentSessions
//
// Revokes Consent Sessions of a Subject for a Specific OAuth 2.0 Client
//
Expand Down Expand Up @@ -146,15 +145,25 @@ func (h *Handler) DeleteConsentSession(w http.ResponseWriter, r *http.Request, p
w.WriteHeader(http.StatusNoContent)
}

// swagger:route GET /admin/oauth2/auth/sessions/consent v1 adminListSubjectConsentSessions
// swagger:parameters adminListOAuth2SubjectConsentSessions
type adminListOAuth2SubjectConsentSessions struct {
x.PaginationHeaders

// The subject to list the consent sessions for.
//
// in: query
// required: true
Subject string `json:"subject"`
}

// swagger:route GET /admin/oauth2/auth/sessions/consent v1 adminListOAuth2SubjectConsentSessions
//
// Lists All Consent Sessions of a Subject
//
// This endpoint lists all subject's granted consent sessions, including client and granted scope.
// If the subject is unknown or has not granted any consent sessions yet, the endpoint returns an
// empty JSON array with status code 200 OK.
//
//
// The "Link" header is also included in successful responses, which contains one or more links for pagination, formatted like so: '<https://hydra-url/admin/oauth2/auth/sessions/consent?subject={user}&limit={limit}&offset={offset}>; rel="{page}"', where page is one of the following applicable pages: 'first', 'next', 'last', and 'previous'.
// Multiple links can be included in this header, and will be separated by a comma.
//
Expand All @@ -168,17 +177,16 @@ func (h *Handler) DeleteConsentSession(w http.ResponseWriter, r *http.Request, p
//
// Responses:
// 200: handledConsentRequestList
// 400: oAuth2ApiError
// 500: oAuth2ApiError
// default: oAuth2ApiError
func (h *Handler) GetConsentSessions(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
subject := r.URL.Query().Get("subject")
if subject == "" {
h.r.Writer().WriteError(w, r, errorsx.WithStack(fosite.ErrInvalidRequest.WithHint(`Query parameter 'subject' is not defined but should have been.`)))
return
}

limit, offset := pagination.Parse(r, 100, 0, 500)
s, err := h.r.ConsentManager().FindSubjectsGrantedConsentRequests(r.Context(), subject, limit, offset)
page, itemsPerPage := x.ParsePagination(r)
s, err := h.r.ConsentManager().FindSubjectsGrantedConsentRequests(r.Context(), subject, itemsPerPage, itemsPerPage*page)
if errors.Is(err, ErrNoPreviousConsentFound) {
h.r.Writer().Write(w, r, []PreviousConsentSession{})
return
Expand All @@ -203,8 +211,7 @@ func (h *Handler) GetConsentSessions(w http.ResponseWriter, r *http.Request, ps
return
}

pagination.Header(w, r.URL, n, limit, offset)

x.PaginationHeader(w, r.URL, int64(n), itemsPerPage, itemsPerPage*page)
h.r.Writer().Write(w, r, a)
}

Expand Down

0 comments on commit bb51ba0

Please sign in to comment.