MCPcopy
hub / github.com/ory/hydra / listOAuth2ConsentSessions

Method listOAuth2ConsentSessions

consent/handler.go:197–234  ·  view source on GitHub ↗

swagger:route GET /admin/oauth2/auth/sessions/consent oAuth2 listOAuth2ConsentSessions # List OAuth 2.0 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 ye

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

195// Extensions:
196// x-ory-ratelimit-bucket: hydra-admin-low
197func (h *Handler) listOAuth2ConsentSessions(w http.ResponseWriter, r *http.Request) {
198 subject := r.URL.Query().Get("subject")
199 if subject == "" {
200 h.r.Writer().WriteError(w, r, errors.WithStack(fosite.ErrInvalidRequest.WithHint(`Query parameter 'subject' is not defined but should have been.`)))
201 return
202 }
203
204 pageKeys := h.r.Config().GetPaginationEncryptionKeys(r.Context())
205 pageOpts, err := keysetpagination.ParseQueryParams(pageKeys, r.URL.Query())
206 if err != nil {
207 h.r.Writer().WriteError(w, r, errors.WithStack(fosite.ErrInvalidRequest.WithWrap(err).WithHintf("Unable to parse pagination parameters: %s", err)))
208 return
209 }
210
211 var requests []flow.Flow
212 var nextPage *keysetpagination.Paginator
213 if loginSessionID := r.URL.Query().Get("login_session_id"); len(loginSessionID) == 0 {
214 requests, nextPage, err = h.r.ConsentManager().FindSubjectsGrantedConsentRequests(r.Context(), subject, pageOpts...)
215 } else {
216 requests, nextPage, err = h.r.ConsentManager().FindSubjectsSessionGrantedConsentRequests(r.Context(), subject, loginSessionID, pageOpts...)
217 }
218 if errors.Is(err, ErrNoPreviousConsentFound) {
219 h.r.Writer().Write(w, r, []flow.OAuth2ConsentSession{})
220 return
221 } else if err != nil {
222 h.r.Writer().WriteError(w, r, err)
223 return
224 }
225
226 // For legacy reasons, this API returns the format like below. Internally, we keep a different format.
227 sessions := make([]*flow.OAuth2ConsentSession, len(requests))
228 for i, f := range requests {
229 sessions[i] = f.ToListConsentSessionResponse()
230 }
231
232 keysetpagination.SetLinkHeader(w, pageKeys, r.URL, nextPage)
233 h.r.Writer().Write(w, r, sessions)
234}
235
236// Revoke OAuth 2.0 Consent Login Sessions Parameters
237//

Callers

nothing calls this directly

Calls 13

WithHintMethod · 0.80
WithHintfMethod · 0.80
WithWrapMethod · 0.80
GetMethod · 0.65
WriterMethod · 0.65
ConfigMethod · 0.65
ConsentManagerMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected