Skip to content

Commit

Permalink
Expose RequestErrorFromOauthError() for public consumption (#24)
Browse files Browse the repository at this point in the history
* Reformat

[#167636840]

Signed-off-by: Andrew Wittrock <awittrock@pivotal.io>
Co-authored-by: Andrew Wittrock <awittrock@pivotal.io>

* Return RetrieveError in passwordcredentials

To match error behavior of golang oauth2 package

[#167636840]

Signed-off-by: Andrew Wittrock <awittrock@pivotal.io>
Co-authored-by: Andrew Wittrock <awittrock@pivotal.io>
  • Loading branch information
2 people authored and joefitzgerald committed Sep 4, 2019
1 parent 80f9ae5 commit 03ff251
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ func (a *API) validatePasswordCredentials() error {
EndpointParams: v,
}
a.passwordCredentialsConfig = c
a.AuthenticatedClient = c.Client(context.WithValue(context.Background(), oauth2.HTTPClient, a.UnauthenticatedClient))
a.AuthenticatedClient = c.Client(context.WithValue(
context.Background(),
oauth2.HTTPClient,
a.UnauthenticatedClient))
return a.ensureTransports()
}

Expand Down
5 changes: 4 additions & 1 deletion passwordcredentials/passwordcredentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func retrieveToken(ctx context.Context, ClientID, ClientSecret, TokenURL string,
return nil, fmt.Errorf("oauth2: cannot fetch token: %v", err)
}
if code := r.StatusCode; code < 200 || code > 299 {
return nil, fmt.Errorf("oauth2: cannot fetch token: %v\nResponse: %s", r.Status, body)
return nil, &oauth2.RetrieveError{
Response: r,
Body: body,
}
}

var token *internalToken
Expand Down

0 comments on commit 03ff251

Please sign in to comment.