Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve http-based warden/introspection error responses #335

Merged
merged 2 commits into from
Dec 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions oauth2/introspector_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func (i *HTTPIntrospector) IntrospectToken(ctx context.Context, token string, sc

body, _ := ioutil.ReadAll(hres.Body)
if hres.StatusCode < 200 || hres.StatusCode >= 300 {
if hres.StatusCode == http.StatusUnauthorized {
return nil, errors.Wrapf(fosite.ErrRequestUnauthorized, "Got status code %d: %s", hres.StatusCode, string(body))
} else if hres.StatusCode == http.StatusForbidden {
return nil, errors.Wrapf(fosite.ErrRequestUnauthorized, "Got status code %d: %s", hres.StatusCode, string(body))
}

return nil, errors.Errorf("Expected 2xx status code but got %d.\n%s", hres.StatusCode, string(body))
} else if err := json.Unmarshal(body, resp); err != nil {
return nil, errors.Errorf("Could not unmarshal body because %s, body %s", err, string(body))
Expand Down
2 changes: 1 addition & 1 deletion warden/warden_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (w *HTTPWarden) IsAllowed(ctx context.Context, a *firewall.AccessRequest) e
if err := agent.POST(a, &allowed); err != nil {
return err
} else if !allowed.Allowed {
return errors.New("Forbidden")
return errors.Wrap(fosite.ErrRequestForbidden, "")
}

return nil
Expand Down