Skip to content

Commit 76fa19c

Browse files
aeneasrarekkas
authored andcommitted
oauth2: improve error responses returned by http introspector
1 parent 812b588 commit 76fa19c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

oauth2/introspector_http.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func (i *HTTPIntrospector) IntrospectToken(ctx context.Context, token string, sc
5555

5656
body, _ := ioutil.ReadAll(hres.Body)
5757
if hres.StatusCode < 200 || hres.StatusCode >= 300 {
58+
if hres.StatusCode == http.StatusUnauthorized {
59+
return nil, errors.Wrapf(fosite.ErrRequestUnauthorized, "Got status code %d: %s", hres.StatusCode, string(body))
60+
} else if hres.StatusCode == http.StatusForbidden {
61+
return nil, errors.Wrapf(fosite.ErrRequestUnauthorized, "Got status code %d: %s", hres.StatusCode, string(body))
62+
}
63+
5864
return nil, errors.Errorf("Expected 2xx status code but got %d.\n%s", hres.StatusCode, string(body))
5965
} else if err := json.Unmarshal(body, resp); err != nil {
6066
return nil, errors.Errorf("Could not unmarshal body because %s, body %s", err, string(body))

0 commit comments

Comments
 (0)