@@ -16,6 +16,8 @@ import (
16
16
"github.com/ory/oathkeeper/driver/configuration"
17
17
"github.com/ory/oathkeeper/helper"
18
18
"github.com/ory/oathkeeper/pipeline"
19
+
20
+ "github.com/ory/x/logrusx"
19
21
)
20
22
21
23
func init () {
@@ -40,12 +42,14 @@ type AuthenticatorCookieSessionConfiguration struct {
40
42
}
41
43
42
44
type AuthenticatorCookieSession struct {
43
- c configuration.Provider
45
+ c configuration.Provider
46
+ logger * logrusx.Logger
44
47
}
45
48
46
- func NewAuthenticatorCookieSession (c configuration.Provider ) * AuthenticatorCookieSession {
49
+ func NewAuthenticatorCookieSession (c configuration.Provider , logger * logrusx. Logger ) * AuthenticatorCookieSession {
47
50
return & AuthenticatorCookieSession {
48
- c : c ,
51
+ c : c ,
52
+ logger : logger ,
49
53
}
50
54
}
51
55
@@ -89,7 +93,7 @@ func (a *AuthenticatorCookieSession) Authenticate(r *http.Request, session *Auth
89
93
return errors .WithStack (ErrAuthenticatorNotResponsible )
90
94
}
91
95
92
- body , err := forwardRequestToSessionStore (r , cf .CheckSessionURL , cf .PreserveQuery , cf .PreservePath , cf .PreserveHost , cf .SetHeaders , cf .ForceMethod )
96
+ body , err := forwardRequestToSessionStore (r , cf .CheckSessionURL , cf .PreserveQuery , cf .PreservePath , cf .PreserveHost , cf .SetHeaders , cf .ForceMethod , a . logger )
93
97
if err != nil {
94
98
return err
95
99
}
@@ -129,7 +133,7 @@ func cookieSessionResponsible(r *http.Request, only []string) bool {
129
133
return false
130
134
}
131
135
132
- func forwardRequestToSessionStore (r * http.Request , checkSessionURL string , preserveQuery bool , preservePath bool , preserveHost bool , setHeaders map [string ]string , m string ) (json.RawMessage , error ) {
136
+ func forwardRequestToSessionStore (r * http.Request , checkSessionURL string , preserveQuery bool , preservePath bool , preserveHost bool , setHeaders map [string ]string , m string , logger * logrusx. Logger ) (json.RawMessage , error ) {
133
137
reqUrl , err := url .Parse (checkSessionURL )
134
138
if err != nil {
135
139
return nil , errors .WithStack (herodot .ErrInternalServerError .WithReasonf ("Unable to parse session check URL: %s" , err ))
@@ -177,12 +181,14 @@ func forwardRequestToSessionStore(r *http.Request, checkSessionURL string, prese
177
181
178
182
body , err := ioutil .ReadAll (res .Body )
179
183
if err != nil {
184
+ logger .Tracef ("Error reading response from remote: %v" , err )
180
185
return json.RawMessage {}, errors .WithStack (herodot .ErrInternalServerError .WithReasonf ("Unable to read response from remote: %s" , err ))
181
186
}
182
187
183
188
if res .StatusCode == 200 {
184
189
return body , nil
185
190
}
186
191
192
+ logger .Tracef ("Remote returned non-200 status code '%d' with body: %s" , res .StatusCode , body )
187
193
return json.RawMessage {}, errors .WithStack (helper .ErrUnauthorized .WithReasonf ("Remote returned non 200 status code: %d" , res .StatusCode ))
188
194
}
0 commit comments