@@ -12,21 +12,18 @@ import (
12
12
13
13
"github.com/gobuffalo/pop/v6"
14
14
"github.com/gofrs/uuid"
15
-
16
- "github.com/ory/hydra/v2/oauth2/flowctx"
17
- "github.com/ory/x/otelx"
18
- "github.com/ory/x/sqlxx"
19
-
20
- "github.com/ory/x/errorsx"
21
-
22
15
"github.com/pkg/errors"
23
16
24
17
"github.com/ory/fosite"
25
18
"github.com/ory/hydra/v2/client"
26
19
"github.com/ory/hydra/v2/consent"
27
20
"github.com/ory/hydra/v2/flow"
21
+ "github.com/ory/hydra/v2/oauth2/flowctx"
28
22
"github.com/ory/hydra/v2/x"
23
+ "github.com/ory/x/errorsx"
24
+ "github.com/ory/x/otelx"
29
25
"github.com/ory/x/sqlcon"
26
+ "github.com/ory/x/sqlxx"
30
27
)
31
28
32
29
var _ consent.Manager = & Persister {}
@@ -51,43 +48,47 @@ func (p *Persister) revokeConsentSession(whereStmt string, whereArgs ...interfac
51
48
if err := p .QueryWithNetwork (ctx ).
52
49
Where (whereStmt , whereArgs ... ).
53
50
Select ("consent_challenge_id" ).
54
- All (& fs ); err != nil {
55
- if errors .Is (err , sql .ErrNoRows ) {
56
- return errorsx .WithStack (x .ErrNotFound )
57
- }
58
-
51
+ All (& fs ); errors .Is (err , sql .ErrNoRows ) {
52
+ return errorsx .WithStack (x .ErrNotFound )
53
+ } else if err != nil {
59
54
return sqlcon .HandleError (err )
60
55
}
61
56
62
- var count int
57
+ ids := make ([]interface {}, 0 , len (fs ))
58
+ nid := p .NetworkID (ctx )
63
59
for _ , f := range fs {
64
- if err := p .RevokeAccessToken (ctx , f .ConsentChallengeID .String ()); errors .Is (err , fosite .ErrNotFound ) {
65
- // do nothing
66
- } else if err != nil {
67
- return err
68
- }
69
-
70
- if err := p .RevokeRefreshToken (ctx , f .ConsentChallengeID .String ()); errors .Is (err , fosite .ErrNotFound ) {
71
- // do nothing
72
- } else if err != nil {
73
- return err
74
- }
75
-
76
- localCount , err := c .RawQuery ("DELETE FROM hydra_oauth2_flow WHERE consent_challenge_id = ? AND nid = ?" , f .ConsentChallengeID , p .NetworkID (ctx )).ExecWithCount ()
77
- if err != nil {
78
- if errors .Is (err , sql .ErrNoRows ) {
79
- return errorsx .WithStack (x .ErrNotFound )
80
- }
81
- return sqlcon .HandleError (err )
82
- }
83
-
84
- // If there are no sessions to revoke we should return an error to indicate to the caller
85
- // that the request failed.
86
- count += localCount
60
+ ids = append (ids , f .ConsentChallengeID .String ())
61
+ }
62
+
63
+ if len (ids ) == 0 {
64
+ return nil
65
+ }
66
+
67
+ if err := p .QueryWithNetwork (ctx ).
68
+ Where ("nid = ?" , nid ).
69
+ Where ("request_id IN (?)" , ids ... ).
70
+ Delete (& OAuth2RequestSQL {Table : sqlTableAccess }); errors .Is (err , fosite .ErrNotFound ) {
71
+ // do nothing
72
+ } else if err != nil {
73
+ return err
87
74
}
88
75
89
- if count == 0 {
76
+ if err := p .QueryWithNetwork (ctx ).
77
+ Where ("nid = ?" , nid ).
78
+ Where ("request_id IN (?)" , ids ... ).
79
+ Delete (& OAuth2RequestSQL {Table : sqlTableRefresh }); errors .Is (err , fosite .ErrNotFound ) {
80
+ // do nothing
81
+ } else if err != nil {
82
+ return err
83
+ }
84
+
85
+ if err := p .QueryWithNetwork (ctx ).
86
+ Where ("nid = ?" , nid ).
87
+ Where ("consent_challenge_id IN (?)" , ids ... ).
88
+ Delete (new (flow.Flow )); errors .Is (err , sql .ErrNoRows ) {
90
89
return errorsx .WithStack (x .ErrNotFound )
90
+ } else if err != nil {
91
+ return sqlcon .HandleError (err )
91
92
}
92
93
93
94
return nil
@@ -642,7 +643,7 @@ SELECT DISTINCT c.* FROM hydra_client as c
642
643
JOIN hydra_oauth2_flow as f ON (c.id = f.client_id AND c.nid = f.nid)
643
644
WHERE
644
645
f.subject=? AND
645
- c.%schannel_logout_uri!= '' AND
646
+ c.%schannel_logout_uri != '' AND
646
647
c.%schannel_logout_uri IS NOT NULL AND
647
648
f.login_session_id = ? AND
648
649
f.nid = ? AND
0 commit comments