@@ -343,6 +343,13 @@ func NewFakeIDP(t testing.TB, opts ...FakeIDPOpt) *FakeIDP {
343
343
idp .realServer (t )
344
344
}
345
345
346
+ // Log the url to indicate which port the IDP is running on if it is
347
+ // being served on a real port.
348
+ idp .logger .Info (context .Background (),
349
+ "fake IDP created" ,
350
+ slog .F ("issuer" , idp .IssuerURL ().String ()),
351
+ )
352
+
346
353
return idp
347
354
}
348
355
@@ -744,7 +751,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
744
751
// This endpoint is required to initialize the OIDC provider.
745
752
// It is used to get the OIDC configuration.
746
753
mux .Get ("/.well-known/openid-configuration" , func (rw http.ResponseWriter , r * http.Request ) {
747
- f .logger .Info (r .Context (), "http OIDC config" , slog . F ( "url" , r . URL . String ()) )
754
+ f .logger .Info (r .Context (), "http OIDC config" , slogRequestFields ( r ) ... )
748
755
749
756
_ = json .NewEncoder (rw ).Encode (f .provider )
750
757
})
@@ -754,7 +761,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
754
761
// w/e and clicking "Allow". They will be redirected back to the redirect
755
762
// when this is done.
756
763
mux .Handle (authorizePath , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
757
- f .logger .Info (r .Context (), "http call authorize" , slog . F ( "url" , r . URL . String ()) )
764
+ f .logger .Info (r .Context (), "http call authorize" , slogRequestFields ( r ) ... )
758
765
759
766
clientID := r .URL .Query ().Get ("client_id" )
760
767
if ! assert .Equal (t , f .clientID , clientID , "unexpected client_id" ) {
@@ -812,11 +819,12 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
812
819
values , err = f .authenticateOIDCClientRequest (t , r )
813
820
}
814
821
f .logger .Info (r .Context (), "http idp call token" ,
815
- slog .F ("url" , r .URL .String ()),
816
- slog .F ("valid" , err == nil ),
817
- slog .F ("grant_type" , values .Get ("grant_type" )),
818
- slog .F ("values" , values .Encode ()),
819
- )
822
+ append (slogRequestFields (r ),
823
+ slog .F ("valid" , err == nil ),
824
+ slog .F ("grant_type" , values .Get ("grant_type" )),
825
+ slog .F ("values" , values .Encode ()),
826
+ )... )
827
+
820
828
if err != nil {
821
829
http .Error (rw , fmt .Sprintf ("invalid token request: %s" , err .Error ()), httpErrorCode (http .StatusBadRequest , err ))
822
830
return
@@ -990,8 +998,10 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
990
998
mux .Handle (userInfoPath , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
991
999
email , ok := validateMW (rw , r )
992
1000
f .logger .Info (r .Context (), "http userinfo endpoint" ,
993
- slog .F ("valid" , ok ),
994
- slog .F ("email" , email ),
1001
+ append (slogRequestFields (r ),
1002
+ slog .F ("valid" , ok ),
1003
+ slog .F ("email" , email ),
1004
+ )... ,
995
1005
)
996
1006
if ! ok {
997
1007
return
@@ -1011,8 +1021,10 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
1011
1021
mux .Mount ("/external-auth-validate/" , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
1012
1022
email , ok := validateMW (rw , r )
1013
1023
f .logger .Info (r .Context (), "http external auth validate" ,
1014
- slog .F ("valid" , ok ),
1015
- slog .F ("email" , email ),
1024
+ append (slogRequestFields (r ),
1025
+ slog .F ("valid" , ok ),
1026
+ slog .F ("email" , email ),
1027
+ )... ,
1016
1028
)
1017
1029
if ! ok {
1018
1030
return
@@ -1028,7 +1040,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
1028
1040
}))
1029
1041
1030
1042
mux .Handle (keysPath , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
1031
- f .logger .Info (r .Context (), "http call idp /keys" )
1043
+ f .logger .Info (r .Context (), "http call idp /keys" , slogRequestFields ( r ) ... )
1032
1044
set := jose.JSONWebKeySet {
1033
1045
Keys : []jose.JSONWebKey {
1034
1046
{
@@ -1042,7 +1054,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
1042
1054
}))
1043
1055
1044
1056
mux .Handle (deviceVerify , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
1045
- f .logger .Info (r .Context (), "http call device verify" )
1057
+ f .logger .Info (r .Context (), "http call device verify" , slogRequestFields ( r ) ... )
1046
1058
1047
1059
inputParam := "user_input"
1048
1060
userInput := r .URL .Query ().Get (inputParam )
@@ -1099,7 +1111,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
1099
1111
}))
1100
1112
1101
1113
mux .Handle (deviceAuth , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
1102
- f .logger .Info (r .Context (), "http call device auth" )
1114
+ f .logger .Info (r .Context (), "http call device auth" , slogRequestFields ( r ) ... )
1103
1115
1104
1116
p := httpapi .NewQueryParamParser ()
1105
1117
p .RequiredNotEmpty ("client_id" )
@@ -1161,7 +1173,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
1161
1173
}))
1162
1174
1163
1175
mux .NotFound (func (rw http.ResponseWriter , r * http.Request ) {
1164
- f .logger .Error (r .Context (), "http call not found" , slog . F ( "path" , r . URL . Path ) )
1176
+ f .logger .Error (r .Context (), "http call not found" , slogRequestFields ( r ) ... )
1165
1177
t .Errorf ("unexpected request to IDP at path %q. Not supported" , r .URL .Path )
1166
1178
})
1167
1179
@@ -1422,6 +1434,14 @@ func (f *FakeIDP) getClaims(m *syncmap.Map[string, jwt.MapClaims], key string) (
1422
1434
return v , true
1423
1435
}
1424
1436
1437
+ func slogRequestFields (r * http.Request ) []any {
1438
+ return []any {
1439
+ slog .F ("url" , r .URL .String ()),
1440
+ slog .F ("host" , r .Host ),
1441
+ slog .F ("method" , r .Method ),
1442
+ }
1443
+ }
1444
+
1425
1445
func httpErrorCode (defaultCode int , err error ) int {
1426
1446
var statusErr statusHookError
1427
1447
status := defaultCode
0 commit comments