Skip to content

Commit

Permalink
fix: downgrade log level for access rejections (#2038)
Browse files Browse the repository at this point in the history
Closes #2031
  • Loading branch information
catper authored Sep 20, 2020
1 parent 077c54a commit 82208c4
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions oauth2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (h *Handler) IntrospectHandler(w http.ResponseWriter, r *http.Request, _ ht

tt, ar, err := h.r.OAuth2Provider().IntrospectToken(ctx, token, fosite.TokenType(tokenType), session, strings.Split(scope, " ")...)
if err != nil {
x.LogError(r, err, h.r.Logger())
x.LogAudit(r, err, h.r.Logger())
err := errors.WithStack(fosite.ErrInactiveToken.WithHint("An introspection strategy indicated that the token is inactive.").WithDebug(err.Error()))
h.r.OAuth2Provider().WriteIntrospectionError(w, err)
return
Expand Down Expand Up @@ -552,8 +552,18 @@ func (h *Handler) TokenHandler(w http.ResponseWriter, r *http.Request) {
var ctx = r.Context()

accessRequest, err := h.r.OAuth2Provider().NewAccessRequest(ctx, r, session)

if err != nil {
x.LogError(r, err, h.r.Logger())
switch errors.Cause(err) {
case fosite.ErrServerError:
fallthrough
case fosite.ErrTemporarilyUnavailable:
fallthrough
case fosite.ErrMisconfiguration:
x.LogError(r, err, h.r.Logger())
default:
x.LogAudit(r, err, h.r.Logger())
}
h.r.OAuth2Provider().WriteAccessError(w, accessRequest, err)
return
}
Expand Down Expand Up @@ -589,8 +599,18 @@ func (h *Handler) TokenHandler(w http.ResponseWriter, r *http.Request) {
}

accessResponse, err := h.r.OAuth2Provider().NewAccessResponse(ctx, accessRequest)

if err != nil {
x.LogError(r, err, h.r.Logger())
switch errors.Cause(err) {
case fosite.ErrServerError:
fallthrough
case fosite.ErrTemporarilyUnavailable:
fallthrough
case fosite.ErrMisconfiguration:
x.LogError(r, err, h.r.Logger())
default:
x.LogAudit(r, err, h.r.Logger())
}
h.r.OAuth2Provider().WriteAccessError(w, accessRequest, err)
return
}
Expand Down

0 comments on commit 82208c4

Please sign in to comment.