Skip to content

Commit 220a774

Browse files
committed
feat: revoke consent by session id. trigger back channel logout.
1 parent 1726b54 commit 220a774

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

consent/handler.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,26 @@ func (h *Handler) DeleteConsentSession(w http.ResponseWriter, r *http.Request, p
135135
}
136136
}
137137
case allClients:
138-
if triggerBackChannelLogout == "true" {
139-
if err := h.r.ConsentStrategy().ExecuteBackChannelLogoutBySubject(r.Context(), r, subject); err != nil {
140-
h.r.Logger().WithError(err).Warn("Unable to execute back channel logout")
138+
if len(loginSessionId) > 0 {
139+
if triggerBackChannelLogout == "true" {
140+
if err := h.r.ConsentStrategy().ExecuteBackChannelLogoutBySession(r.Context(), r, subject, loginSessionId); err != nil {
141+
h.r.Logger().WithError(err).Warn("Unable to execute back channel logout")
142+
}
143+
}
144+
if err := h.r.ConsentManager().RevokeLoginSessionConsentSession(r.Context(), loginSessionId); err != nil && !errors.Is(err, x.ErrNotFound) {
145+
h.r.Writer().WriteError(w, r, err)
146+
return
147+
}
148+
} else {
149+
if triggerBackChannelLogout == "true" {
150+
if err := h.r.ConsentStrategy().ExecuteBackChannelLogoutBySubject(r.Context(), r, subject); err != nil {
151+
h.r.Logger().WithError(err).Warn("Unable to execute back channel logout")
152+
}
153+
}
154+
if err := h.r.ConsentManager().RevokeSubjectConsentSession(r.Context(), subject); err != nil && !errors.Is(err, x.ErrNotFound) {
155+
h.r.Writer().WriteError(w, r, err)
156+
return
141157
}
142-
}
143-
if err := h.r.ConsentManager().RevokeSubjectConsentSession(r.Context(), subject); err != nil && !errors.Is(err, x.ErrNotFound) {
144-
h.r.Writer().WriteError(w, r, err)
145-
return
146158
}
147159
default:
148160
h.r.Writer().WriteError(w, r, errorsx.WithStack(fosite.ErrInvalidRequest.WithHint(`Query parameter both 'client' and 'all' is not defined but one of them should have been.`)))

consent/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Manager interface {
4242
GetConsentRequest(ctx context.Context, challenge string) (*ConsentRequest, error)
4343
HandleConsentRequest(ctx context.Context, challenge string, r *HandledConsentRequest) (*ConsentRequest, error)
4444
RevokeSubjectConsentSession(ctx context.Context, user string) error
45+
RevokeLoginSessionConsentSession(ctx context.Context, loginSessionId string) error
4546
RevokeSubjectClientConsentSession(ctx context.Context, user, client string) error
4647
RevokeSubjectClientLoginSessionConsentSession(ctx context.Context, user, client, loginSessionId string) error
4748

persistence/sql/persister_consent.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func (p *Persister) RevokeSubjectConsentSession(ctx context.Context, user string
2828
return p.transaction(ctx, p.revokeConsentSession("r.subject = ?", user))
2929
}
3030

31+
func (p *Persister) RevokeLoginSessionConsentSession(ctx context.Context, loginSessionId string) error {
32+
return p.transaction(ctx, p.revokeConsentSession("r.login_session_id = ?", loginSessionId))
33+
}
34+
3135
func (p *Persister) RevokeSubjectClientConsentSession(ctx context.Context, user, client string) error {
3236
return p.transaction(ctx, p.revokeConsentSession("r.subject = ? AND r.client_id = ?", user, client))
3337
}

0 commit comments

Comments
 (0)