Skip to content

Commit

Permalink
When introspection fails return unauthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored and arekkas committed Oct 18, 2017
1 parent 2214498 commit f5295b4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions director/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (d *Director) Director(r *http.Request) {
*r = *r.WithContext(context.WithValue(r.Context(), requestDenied, &directorError{err: err, statusCode: http.StatusForbidden}))
case helper.ErrMissingBearerToken:
*r = *r.WithContext(context.WithValue(r.Context(), requestDenied, &directorError{err: err, statusCode: http.StatusUnauthorized}))
case helper.ErrUnauthorized:
*r = *r.WithContext(context.WithValue(r.Context(), requestDenied, &directorError{err: err, statusCode: http.StatusUnauthorized}))
case helper.ErrMatchesNoRule:
*r = *r.WithContext(context.WithValue(r.Context(), requestDenied, &directorError{err: err, statusCode: http.StatusNotFound}))
case helper.ErrMatchesMoreThanOneRule:
Expand Down
2 changes: 1 addition & 1 deletion evaluator/evaluator_warden.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (d *WardenEvaluator) EvaluateAccessRequest(r *http.Request) (*Session, erro
Errorf("Expected warden response to return status code 200.")
return nil, errors.Errorf("Token introspection expects status code %d but got %d", http.StatusOK, response.StatusCode)
} else if !introspection.Active {
return nil, errors.WithStack(helper.ErrForbidden)
return nil, errors.WithStack(helper.ErrUnauthorized)
}

return &Session{
Expand Down
1 change: 1 addition & 0 deletions helper/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "github.com/pkg/errors"
var (
ErrMissingBearerToken = errors.New("This action requires authorization but no bearer token was given")
ErrForbidden = errors.New("Access credentials are not sufficient to access this resource")
ErrUnauthorized = errors.New("Access credentials are either expired or missing a scope")
ErrMatchesMoreThanOneRule = errors.New("Expected exactly one rule but found multiple rules")
ErrMatchesNoRule = errors.New("Requested url does not match any rules")
ErrResourceNotFound = errors.New("The requested resource could not be found")
Expand Down

0 comments on commit f5295b4

Please sign in to comment.