oauth2: add error type for unsuccessful token endpoint status

Allows the HTTP response and body to be extracted without parsing
the error string, but keeps backwards compatibility for users who
are currently doing so.

Fixes golang/oauth2#173

Change-Id: Id7709da827a155299b047f0bcb74aa8f91b01e96
Reviewed-on: https://go-review.googlesource.com/84156
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Tim Cooper
2017-12-14 19:38:05 -04:00
committed by Brad Fitzpatrick
parent 462316686f
commit 0448841f0c
4 changed files with 59 additions and 1 deletions

View File

@@ -92,6 +92,9 @@ func (c *tokenSource) Token() (*oauth2.Token, error) {
}
tk, err := internal.RetrieveToken(c.ctx, c.conf.ClientID, c.conf.ClientSecret, c.conf.TokenURL, v)
if err != nil {
if rErr, ok := err.(*internal.RetrieveError); ok {
return nil, (*oauth2.RetrieveError)(rErr)
}
return nil, err
}
t := &oauth2.Token{