Closed
Description
Motivation: make it easier for apps to show readable errors to users
OAuth spec RFC 6749 defines JSON error responses with three parameters: error
, error_description
and error_uri
. https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
However error type oauth2.RetrieveError merely holds the raw response body unparsed.
For clients to more easily handle errors and show users readable error messages, it would greatly help to parse JSON error responses and populate corresponding fields:
// RetrieveError is the error returned when the token endpoint returns a
+ // non-2XX HTTP status code or populates RFC 6749's 'error' parameter.
+ // https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
type RetrieveError struct {
Response *http.Response
// Body is the body that was consumed by reading Response.Body.
// It may be truncated.
Body []byte
+ // ErrorCode is RFC 6749's 'error' parameter.
+ ErrorCode string
+ // ErrorDescription is RFC 6749's 'error_description' parameter.
+ ErrorDescription string
+ // ErrorURI is RFC 6749's 'error_uri' parameter.
+ ErrorURI string
}
The ErrorCode field is so named to avoid conflict with the Error() method.
Would it be acceptable to change the string returned by the Error() method to be more user friendly when these fields are set?
Here's a change including parsing logic golang/oauth2#610