diff options
| author | 2023-05-15 12:23:08 +0200 | |
|---|---|---|
| committer | 2023-05-15 12:23:08 +0200 | |
| commit | e1b7ab26035a1e1d558c6fc5c507c7b7fca287b3 (patch) | |
| tree | 1a30c7e9a3e61b375f5374f9745d2dd3a7763bf7 /vendor/golang.org/x/oauth2 | |
| parent | [bugfix] update go-cache to v3.3.3 (#1778) (diff) | |
| download | gotosocial-e1b7ab26035a1e1d558c6fc5c507c7b7fca287b3.tar.xz | |
[chore]: Bump golang.org/x/oauth2 from 0.7.0 to 0.8.0 (#1785)
Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.7.0 to 0.8.0.
- [Commits](https://github.com/golang/oauth2/compare/v0.7.0...v0.8.0)
---
updated-dependencies:
- dependency-name: golang.org/x/oauth2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/golang.org/x/oauth2')
| -rw-r--r-- | vendor/golang.org/x/oauth2/internal/oauth2.go | 2 | ||||
| -rw-r--r-- | vendor/golang.org/x/oauth2/internal/token.go | 60 | ||||
| -rw-r--r-- | vendor/golang.org/x/oauth2/token.go | 19 | 
3 files changed, 69 insertions, 12 deletions
diff --git a/vendor/golang.org/x/oauth2/internal/oauth2.go b/vendor/golang.org/x/oauth2/internal/oauth2.go index c0ab196cf..14989beaf 100644 --- a/vendor/golang.org/x/oauth2/internal/oauth2.go +++ b/vendor/golang.org/x/oauth2/internal/oauth2.go @@ -14,7 +14,7 @@ import (  // ParseKey converts the binary contents of a private key file  // to an *rsa.PrivateKey. It detects whether the private key is in a -// PEM container or not. If so, it extracts the the private key +// PEM container or not. If so, it extracts the private key  // from PEM container before conversion. It only supports PEM  // containers with no passphrase.  func ParseKey(key []byte) (*rsa.PrivateKey, error) { diff --git a/vendor/golang.org/x/oauth2/internal/token.go b/vendor/golang.org/x/oauth2/internal/token.go index b4723fcac..58901bda5 100644 --- a/vendor/golang.org/x/oauth2/internal/token.go +++ b/vendor/golang.org/x/oauth2/internal/token.go @@ -55,12 +55,18 @@ type Token struct {  }  // tokenJSON is the struct representing the HTTP response from OAuth2 -// providers returning a token in JSON form. +// providers returning a token or error in JSON form. +// https://datatracker.ietf.org/doc/html/rfc6749#section-5.1  type tokenJSON struct {  	AccessToken  string         `json:"access_token"`  	TokenType    string         `json:"token_type"`  	RefreshToken string         `json:"refresh_token"`  	ExpiresIn    expirationTime `json:"expires_in"` // at least PayPal returns string, while most return number +	// error fields +	// https://datatracker.ietf.org/doc/html/rfc6749#section-5.2 +	ErrorCode        string `json:"error"` +	ErrorDescription string `json:"error_description"` +	ErrorURI         string `json:"error_uri"`  }  func (e *tokenJSON) expiry() (t time.Time) { @@ -236,21 +242,29 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) {  	if err != nil {  		return nil, fmt.Errorf("oauth2: cannot fetch token: %v", err)  	} -	if code := r.StatusCode; code < 200 || code > 299 { -		return nil, &RetrieveError{ -			Response: r, -			Body:     body, -		} + +	failureStatus := r.StatusCode < 200 || r.StatusCode > 299 +	retrieveError := &RetrieveError{ +		Response: r, +		Body:     body, +		// attempt to populate error detail below  	}  	var token *Token  	content, _, _ := mime.ParseMediaType(r.Header.Get("Content-Type"))  	switch content {  	case "application/x-www-form-urlencoded", "text/plain": +		// some endpoints return a query string  		vals, err := url.ParseQuery(string(body))  		if err != nil { -			return nil, err +			if failureStatus { +				return nil, retrieveError +			} +			return nil, fmt.Errorf("oauth2: cannot parse response: %v", err)  		} +		retrieveError.ErrorCode = vals.Get("error") +		retrieveError.ErrorDescription = vals.Get("error_description") +		retrieveError.ErrorURI = vals.Get("error_uri")  		token = &Token{  			AccessToken:  vals.Get("access_token"),  			TokenType:    vals.Get("token_type"), @@ -265,8 +279,14 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) {  	default:  		var tj tokenJSON  		if err = json.Unmarshal(body, &tj); err != nil { -			return nil, err +			if failureStatus { +				return nil, retrieveError +			} +			return nil, fmt.Errorf("oauth2: cannot parse json: %v", err)  		} +		retrieveError.ErrorCode = tj.ErrorCode +		retrieveError.ErrorDescription = tj.ErrorDescription +		retrieveError.ErrorURI = tj.ErrorURI  		token = &Token{  			AccessToken:  tj.AccessToken,  			TokenType:    tj.TokenType, @@ -276,17 +296,37 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) {  		}  		json.Unmarshal(body, &token.Raw) // no error checks for optional fields  	} +	// according to spec, servers should respond status 400 in error case +	// https://www.rfc-editor.org/rfc/rfc6749#section-5.2 +	// but some unorthodox servers respond 200 in error case +	if failureStatus || retrieveError.ErrorCode != "" { +		return nil, retrieveError +	}  	if token.AccessToken == "" {  		return nil, errors.New("oauth2: server response missing access_token")  	}  	return token, nil  } +// mirrors oauth2.RetrieveError  type RetrieveError struct { -	Response *http.Response -	Body     []byte +	Response         *http.Response +	Body             []byte +	ErrorCode        string +	ErrorDescription string +	ErrorURI         string  }  func (r *RetrieveError) Error() string { +	if r.ErrorCode != "" { +		s := fmt.Sprintf("oauth2: %q", r.ErrorCode) +		if r.ErrorDescription != "" { +			s += fmt.Sprintf(" %q", r.ErrorDescription) +		} +		if r.ErrorURI != "" { +			s += fmt.Sprintf(" %q", r.ErrorURI) +		} +		return s +	}  	return fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", r.Response.Status, r.Body)  } diff --git a/vendor/golang.org/x/oauth2/token.go b/vendor/golang.org/x/oauth2/token.go index 7c64006de..5ffce9764 100644 --- a/vendor/golang.org/x/oauth2/token.go +++ b/vendor/golang.org/x/oauth2/token.go @@ -175,14 +175,31 @@ func retrieveToken(ctx context.Context, c *Config, v url.Values) (*Token, error)  }  // RetrieveError is the error returned when the token endpoint returns a -// non-2XX HTTP status code. +// 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  }  func (r *RetrieveError) Error() string { +	if r.ErrorCode != "" { +		s := fmt.Sprintf("oauth2: %q", r.ErrorCode) +		if r.ErrorDescription != "" { +			s += fmt.Sprintf(" %q", r.ErrorDescription) +		} +		if r.ErrorURI != "" { +			s += fmt.Sprintf(" %q", r.ErrorURI) +		} +		return s +	}  	return fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", r.Response.Status, r.Body)  }  | 
