4
4
package consent
5
5
6
6
import (
7
- "context"
8
7
"encoding/json"
9
8
"net/http"
10
9
"net/url"
@@ -80,7 +79,6 @@ type revokeOAuth2ConsentSessions struct {
80
79
// The subject whose consent sessions should be deleted.
81
80
//
82
81
// in: query
83
- // required: true
84
82
Subject string `json:"subject"`
85
83
86
84
// OAuth 2.0 Client ID
@@ -90,6 +88,13 @@ type revokeOAuth2ConsentSessions struct {
90
88
// in: query
91
89
Client string `json:"client"`
92
90
91
+ // Consent Challenge ID
92
+ //
93
+ // If set, revoke all token chains derived from this particular consent request ID.
94
+ //
95
+ // in: query
96
+ ConsentChallengeID string `json:"consent_challenge_id"`
97
+
93
98
// Revoke All Consent Sessions
94
99
//
95
100
// If set to `true` deletes all consent sessions by the Subject that have been granted.
@@ -119,14 +124,23 @@ type revokeOAuth2ConsentSessions struct {
119
124
func (h * Handler ) revokeOAuth2ConsentSessions (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
120
125
subject := r .URL .Query ().Get ("subject" )
121
126
client := r .URL .Query ().Get ("client" )
127
+ consentChallengeID := r .URL .Query ().Get ("consent_challenge_id" )
122
128
allClients := r .URL .Query ().Get ("all" ) == "true"
123
- if subject == "" {
124
- h .r .Writer ().WriteError (w , r , errorsx .WithStack (fosite .ErrInvalidRequest .WithHint (`Query parameter 'subject' is not defined but should have been.` )))
129
+ if subject == "" && consentChallengeID == "" {
130
+ h .r .Writer ().WriteError (w , r , errorsx .WithStack (fosite .ErrInvalidRequest .WithHint (`Query parameter 'subject' or 'consent_challenge_id' are required.` )))
131
+ return
132
+ }
133
+ if consentChallengeID != "" && subject != "" {
134
+ h .r .Writer ().WriteError (w , r , errorsx .WithStack (fosite .ErrInvalidRequest .WithHint (`Query parameter 'subject' and 'consent_challenge_id' cannot be set at the same time.` )))
135
+ return
136
+ }
137
+ if consentChallengeID != "" && client != "" {
138
+ h .r .Writer ().WriteError (w , r , errorsx .WithStack (fosite .ErrInvalidRequest .WithHint (`Query parameter 'client' and 'consent_challenge_id' cannot be set at the same time.` )))
125
139
return
126
140
}
127
141
128
142
switch {
129
- case len ( client ) > 0 :
143
+ case client != "" :
130
144
if err := h .r .ConsentManager ().RevokeSubjectClientConsentSession (r .Context (), subject , client ); err != nil && ! errors .Is (err , x .ErrNotFound ) {
131
145
h .r .Writer ().WriteError (w , r , err )
132
146
return
@@ -138,6 +152,12 @@ func (h *Handler) revokeOAuth2ConsentSessions(w http.ResponseWriter, r *http.Req
138
152
return
139
153
}
140
154
events .Trace (r .Context (), events .ConsentRevoked , events .WithSubject (subject ))
155
+ case consentChallengeID != "" :
156
+ if err := h .r .ConsentManager ().RevokeConsentSessionByID (r .Context (), consentChallengeID ); err != nil && ! errors .Is (err , x .ErrNotFound ) {
157
+ h .r .Writer ().WriteError (w , r , err )
158
+ return
159
+ }
160
+ return
141
161
default :
142
162
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.` )))
143
163
return
@@ -479,7 +499,7 @@ func (h *Handler) acceptOAuth2LoginRequest(w http.ResponseWriter, r *http.Reques
479
499
}
480
500
handledLoginRequest .RequestedAt = loginRequest .RequestedAt
481
501
482
- f , err := h . decodeFlowWithClient (ctx , challenge , flowctx .AsLoginChallenge )
502
+ f , err := flowctx . Decode [flow. Flow ] (ctx , h . r . FlowCipher () , challenge , flowctx .AsLoginChallenge )
483
503
if err != nil {
484
504
h .r .Writer ().WriteError (w , r , err )
485
505
return
@@ -579,11 +599,12 @@ func (h *Handler) rejectOAuth2LoginRequest(w http.ResponseWriter, r *http.Reques
579
599
return
580
600
}
581
601
582
- f , err := h . decodeFlowWithClient (ctx , challenge , flowctx .AsLoginChallenge )
602
+ f , err := flowctx . Decode [flow. Flow ] (ctx , h . r . FlowCipher () , challenge , flowctx .AsLoginChallenge )
583
603
if err != nil {
584
604
h .r .Writer ().WriteError (w , r , err )
585
605
return
586
606
}
607
+
587
608
request , err := h .r .ConsentManager ().HandleLoginRequest (ctx , f , challenge , & flow.HandledLoginRequest {
588
609
Error : & p ,
589
610
ID : challenge ,
@@ -765,11 +786,12 @@ func (h *Handler) acceptOAuth2ConsentRequest(w http.ResponseWriter, r *http.Requ
765
786
p .RequestedAt = cr .RequestedAt
766
787
p .HandledAt = sqlxx .NullTime (time .Now ().UTC ())
767
788
768
- f , err := h . decodeFlowWithClient (ctx , challenge , flowctx .AsConsentChallenge )
789
+ f , err := flowctx . Decode [flow. Flow ] (ctx , h . r . FlowCipher () , challenge , flowctx .AsConsentChallenge )
769
790
if err != nil {
770
791
h .r .Writer ().WriteError (w , r , err )
771
792
return
772
793
}
794
+
773
795
hr , err := h .r .ConsentManager ().HandleConsentRequest (ctx , f , & p )
774
796
if err != nil {
775
797
h .r .Writer ().WriteError (w , r , errorsx .WithStack (err ))
@@ -872,7 +894,7 @@ func (h *Handler) rejectOAuth2ConsentRequest(w http.ResponseWriter, r *http.Requ
872
894
return
873
895
}
874
896
875
- f , err := h . decodeFlowWithClient (ctx , challenge , flowctx .AsConsentChallenge )
897
+ f , err := flowctx . Decode [flow. Flow ] (ctx , h . r . FlowCipher () , challenge , flowctx .AsConsentChallenge )
876
898
if err != nil {
877
899
h .r .Writer ().WriteError (w , r , err )
878
900
return
@@ -1048,12 +1070,3 @@ func (h *Handler) getOAuth2LogoutRequest(w http.ResponseWriter, r *http.Request,
1048
1070
1049
1071
h .r .Writer ().Write (w , r , request )
1050
1072
}
1051
-
1052
- func (h * Handler ) decodeFlowWithClient (ctx context.Context , challenge string , opts ... flowctx.CodecOption ) (* flow.Flow , error ) {
1053
- f , err := flowctx .Decode [flow.Flow ](ctx , h .r .FlowCipher (), challenge , opts ... )
1054
- if err != nil {
1055
- return nil , err
1056
- }
1057
-
1058
- return f , nil
1059
- }
0 commit comments