Skip to content

Commit

Permalink
introspection: Improves debug messages (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas committed Mar 17, 2018
1 parent b6380be commit 338399b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions introspection_request_handler.go
Expand Up @@ -127,32 +127,32 @@ func (f *Fosite) NewIntrospectionRequest(ctx context.Context, r *http.Request, s
}

if _, err := f.IntrospectToken(ctx, clientToken, AccessToken, session.Clone()); err != nil {
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("HTTP Authorization header missing.WithDebug(malformed or credentials used are invalid"))
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("HTTP Authorization header missing, malformed, or credentials used are invalid"))
}
} else {
id, secret, ok := r.BasicAuth()
if !ok {
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("HTTP Authorization header missing.WithDebug(malformed or credentials used are invalid"))
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("HTTP Authorization header missing"))
}

clientID, err := url.QueryUnescape(id)
if err != nil {
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("HTTP Authorization header missing.WithDebug(malformed or credentials used are invalid"))
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("Unable to decode OAuth 2.0 Client ID from HTTP basic authorization header"))
}

clientSecret, err := url.QueryUnescape(secret)
if err != nil {
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("HTTP Authorization header missing.WithDebug(malformed or credentials used are invalid"))
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("Unable to decode OAuth 2.0 Client Secret from HTTP basic authorization header"))
}

client, err := f.Store.GetClient(ctx, clientID)
if err != nil {
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("HTTP Authorization header missing.WithDebug(malformed or credentials used are invalid"))
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("Unable to find OAuth 2.0 Client from HTTP basic authorization header"))
}

// Enforce client authentication
if err := f.Hasher.Compare(client.GetHashedSecret(), []byte(clientSecret)); err != nil {
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("HTTP Authorization header missing.WithDebug(malformed or credentials used are invalid"))
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrRequestUnauthorized.WithDebug("OAuth 2.0 Client credentials are invalid"))
}
}

Expand Down
4 changes: 2 additions & 2 deletions introspection_response_writer.go
Expand Up @@ -55,8 +55,8 @@ func (f *Fosite) WriteIntrospectionError(rw http.ResponseWriter, err error) {
return
}

switch errors.Cause(err) {
case ErrInvalidRequest, ErrRequestUnauthorized:
switch errors.Cause(err).Error() {
case ErrInvalidRequest.Error(), ErrRequestUnauthorized.Error():
f.writeJsonError(rw, err)
return
}
Expand Down

0 comments on commit 338399b

Please sign in to comment.