@@ -21,14 +21,13 @@ import (
21
21
"github.com/sirupsen/logrus"
22
22
"go.opentelemetry.io/otel/trace"
23
23
24
- "github.com/ory/hydra/v2/flow"
25
- "github.com/ory/hydra/v2/oauth2/flowctx"
26
-
27
24
"github.com/ory/fosite"
28
25
"github.com/ory/fosite/handler/openid"
29
26
"github.com/ory/fosite/token/jwt"
30
27
"github.com/ory/hydra/v2/client"
31
28
"github.com/ory/hydra/v2/driver/config"
29
+ "github.com/ory/hydra/v2/flow"
30
+ "github.com/ory/hydra/v2/oauth2/flowctx"
32
31
"github.com/ory/hydra/v2/x"
33
32
"github.com/ory/x/errorsx"
34
33
"github.com/ory/x/mapx"
@@ -855,21 +854,18 @@ func (s *DefaultStrategy) issueLogoutVerifier(ctx context.Context, w http.Respon
855
854
return nil , err
856
855
}
857
856
858
- challenge := uuid .New ()
859
- if err := s .r .ConsentManager ().CreateLogoutRequest (r .Context (), & flow.LogoutRequest {
860
- RequestURL : r .URL .String (),
861
- ID : challenge ,
862
- Subject : session .Subject ,
863
- SessionID : session .ID ,
864
- Verifier : uuid .New (),
865
- RequestedAt : sqlxx .NullTime (time .Now ().UTC ().Round (time .Second )),
866
- ExpiresAt : sqlxx .NullTime (time .Now ().UTC ().Round (time .Second ).Add (s .c .ConsentRequestMaxAge (ctx ))),
867
- RPInitiated : false ,
868
-
869
- // PostLogoutRedirectURI is set to the value from config.Provider().LogoutRedirectURL()
857
+ now := time .Now ().UTC ().Round (time .Second )
858
+ challenge , err := s .r .ConsentManager ().CreateLogoutChallenge (ctx , & flow.LogoutRequest {
859
+ RequestURL : r .URL .String (),
860
+ Subject : session .Subject ,
861
+ SessionID : session .ID ,
862
+ RequestedAt : now ,
863
+ ExpiresAt : now .Add (s .c .ConsentRequestMaxAge (ctx )),
864
+ RPInitiated : false ,
870
865
PostLogoutRedirectURI : redir ,
871
- }); err != nil {
872
- return nil , err
866
+ })
867
+ if err != nil {
868
+ return nil , errors .WithStack (err )
873
869
}
874
870
875
871
s .r .AuditLogger ().
@@ -895,13 +891,13 @@ func (s *DefaultStrategy) issueLogoutVerifier(ctx context.Context, w http.Respon
895
891
)
896
892
}
897
893
898
- now := time .Now ().UTC ().Unix ( )
899
- if ! claims .VerifyIssuedAt (now , true ) {
894
+ now := time .Now ().UTC ().Round ( time . Second )
895
+ if ! claims .VerifyIssuedAt (now . Unix () , true ) {
900
896
return nil , errorsx .WithStack (fosite .ErrInvalidRequest .
901
897
WithHintf (
902
898
`Logout failed because iat claim value '%.0f' from query parameter id_token_hint is before now ('%d').` ,
903
899
mapx .GetFloat64Default (mksi , "iat" , float64 (0 )),
904
- now ,
900
+ now . Unix () ,
905
901
),
906
902
)
907
903
}
@@ -939,6 +935,7 @@ func (s *DefaultStrategy) issueLogoutVerifier(ctx context.Context, w http.Respon
939
935
return nil , errorsx .WithStack (fosite .ErrInvalidRequest .
940
936
WithHint ("Logout failed because none of the listed audiences is a registered OAuth 2.0 Client." ))
941
937
}
938
+ cl .Secret = "" // We don't want to expose the client secret.
942
939
943
940
if len (requestedRedir ) > 0 {
944
941
var f * url.URL
@@ -979,20 +976,19 @@ func (s *DefaultStrategy) issueLogoutVerifier(ctx context.Context, w http.Respon
979
976
return nil , err
980
977
}
981
978
982
- challenge := uuid .New ()
983
- if err := s .r .ConsentManager ().CreateLogoutRequest (r .Context (), & flow.LogoutRequest {
984
- RequestURL : r .URL .String (),
985
- ID : challenge ,
986
- SessionID : hintSid ,
987
- Subject : session .Subject ,
988
- Verifier : uuid .New (),
989
- Client : cl ,
990
- RPInitiated : true ,
991
-
992
- // PostLogoutRedirectURI is set to the value from config.Provider().LogoutRedirectURL()
979
+ now = time .Now ().UTC ().Round (time .Second )
980
+ challenge , err := s .r .ConsentManager ().CreateLogoutChallenge (ctx , & flow.LogoutRequest {
981
+ RequestURL : r .URL .String (),
982
+ Subject : session .Subject ,
983
+ SessionID : hintSid ,
984
+ RequestedAt : now ,
985
+ ExpiresAt : now .Add (s .c .ConsentRequestMaxAge (ctx )),
986
+ RPInitiated : true ,
993
987
PostLogoutRedirectURI : redir ,
994
- }); err != nil {
995
- return nil , err
988
+ Client : cl ,
989
+ })
990
+ if err != nil {
991
+ return nil , errors .WithStack (err )
996
992
}
997
993
998
994
http .Redirect (w , r , urlx .SetQuery (s .c .LogoutURL (ctx ), url.Values {"logout_challenge" : {challenge }}).String (), http .StatusFound )
0 commit comments