Skip to content

Commit 7eb8e6e

Browse files
committed
Chore: introduce logger
1 parent 3ce1f82 commit 7eb8e6e

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

driver/configuration/provider_viper_public_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func TestViperProvider(t *testing.T) {
258258
})
259259

260260
t.Run("authenticator=cookie_session", func(t *testing.T) {
261-
a := authn.NewAuthenticatorCookieSession(p)
261+
a := authn.NewAuthenticatorCookieSession(p, logger)
262262
assert.True(t, p.AuthenticatorIsEnabled(a.GetID()))
263263
require.NoError(t, a.Validate(nil))
264264

driver/registry_memory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ func (r *RegistryMemory) prepareAuthn() {
365365
if r.authenticators == nil {
366366
interim := []authn.Authenticator{
367367
authn.NewAuthenticatorAnonymous(r.c),
368-
authn.NewAuthenticatorCookieSession(r.c),
369-
authn.NewAuthenticatorBearerToken(r.c),
368+
authn.NewAuthenticatorCookieSession(r.c, r.Logger()),
369+
authn.NewAuthenticatorBearerToken(r.c, r.Logger()),
370370
authn.NewAuthenticatorJWT(r.c, r),
371371
authn.NewAuthenticatorNoOp(r.c),
372372
authn.NewAuthenticatorOAuth2ClientCredentials(r.c),

pipeline/authn/authenticator_bearer_token.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/ory/oathkeeper/driver/configuration"
1313
"github.com/ory/oathkeeper/helper"
1414
"github.com/ory/oathkeeper/pipeline"
15+
16+
"github.com/ory/x/logrusx"
1517
)
1618

1719
func init() {
@@ -36,12 +38,14 @@ type AuthenticatorBearerTokenConfiguration struct {
3638
}
3739

3840
type AuthenticatorBearerToken struct {
39-
c configuration.Provider
41+
c configuration.Provider
42+
logger *logrusx.Logger
4043
}
4144

42-
func NewAuthenticatorBearerToken(c configuration.Provider) *AuthenticatorBearerToken {
45+
func NewAuthenticatorBearerToken(c configuration.Provider, logger *logrusx.Logger) *AuthenticatorBearerToken {
4346
return &AuthenticatorBearerToken{
44-
c: c,
47+
c: c,
48+
logger: logger,
4549
}
4650
}
4751

@@ -86,7 +90,7 @@ func (a *AuthenticatorBearerToken) Authenticate(r *http.Request, session *Authen
8690
return errors.WithStack(ErrAuthenticatorNotResponsible)
8791
}
8892

89-
body, err := forwardRequestToSessionStore(r, cf.CheckSessionURL, cf.PreserveQuery, cf.PreservePath, cf.PreserveHost, cf.SetHeaders, cf.ForceMethod)
93+
body, err := forwardRequestToSessionStore(r, cf.CheckSessionURL, cf.PreserveQuery, cf.PreservePath, cf.PreserveHost, cf.SetHeaders, cf.ForceMethod, a.logger)
9094
if err != nil {
9195
return err
9296
}

pipeline/authn/authenticator_cookie_session.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/ory/oathkeeper/driver/configuration"
1717
"github.com/ory/oathkeeper/helper"
1818
"github.com/ory/oathkeeper/pipeline"
19+
20+
"github.com/ory/x/logrusx"
1921
)
2022

2123
func init() {
@@ -40,12 +42,14 @@ type AuthenticatorCookieSessionConfiguration struct {
4042
}
4143

4244
type AuthenticatorCookieSession struct {
43-
c configuration.Provider
45+
c configuration.Provider
46+
logger *logrusx.Logger
4447
}
4548

46-
func NewAuthenticatorCookieSession(c configuration.Provider) *AuthenticatorCookieSession {
49+
func NewAuthenticatorCookieSession(c configuration.Provider, logger *logrusx.Logger) *AuthenticatorCookieSession {
4750
return &AuthenticatorCookieSession{
48-
c: c,
51+
c: c,
52+
logger: logger,
4953
}
5054
}
5155

@@ -89,7 +93,7 @@ func (a *AuthenticatorCookieSession) Authenticate(r *http.Request, session *Auth
8993
return errors.WithStack(ErrAuthenticatorNotResponsible)
9094
}
9195

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)
9397
if err != nil {
9498
return err
9599
}
@@ -129,7 +133,7 @@ func cookieSessionResponsible(r *http.Request, only []string) bool {
129133
return false
130134
}
131135

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) {
133137
reqUrl, err := url.Parse(checkSessionURL)
134138
if err != nil {
135139
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
177181

178182
body, err := ioutil.ReadAll(res.Body)
179183
if err != nil {
184+
logger.Tracef("Error reading response from remote: %v", err)
180185
return json.RawMessage{}, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("Unable to read response from remote: %s", err))
181186
}
182187

183188
if res.StatusCode == 200 {
184189
return body, nil
185190
}
186191

192+
logger.Tracef("Remote returned non-200 status code '%d' with body: %s", res.StatusCode, body)
187193
return json.RawMessage{}, errors.WithStack(helper.ErrUnauthorized.WithReasonf("Remote returned non 200 status code: %d", res.StatusCode))
188194
}

0 commit comments

Comments
 (0)