Open platform to collect and prioritize feedback
chore: update oauth2 package (#289)
Guilherme Oenning46db19801c40
diff --git a/Gopkg.lock b/Gopkg.lockindex 0a2889377..7862d5151 100644--- a/Gopkg.lock+++ b/Gopkg.lock@@ -138,7 +138,7 @@"jws","jwt"]- revision = "13449ad91cb26cb47661c1b080790392170385fd"+ revision = "2f32c3ac0fa4fb807a0fcefb0b6f2468a0d99bd0"[[projects]]name = "google.golang.org/appengine"@@ -166,6 +166,6 @@[solve-meta]analyzer-name = "dep"analyzer-version = 1- inputs-digest = "0417bf0aaacf11facc05a78cfc1c2607ce5aa876290f69bacd2fe7a7802bddf4"+ inputs-digest = "3661aaca7b7d96c470d0a172f6d6bd67d7bc3ee3bca7d00eb4a5f90abf352247"solver-name = "gps-cdcl"solver-version = 1diff --git a/Gopkg.toml b/Gopkg.tomlindex fb378bd5e..f1ee52a9a 100644--- a/Gopkg.toml+++ b/Gopkg.toml@@ -27,7 +27,7 @@[[constraint]]name = "github.com/gosimple/slug"- version = "1.0.3"+ version = "=1.1.1"[[constraint]]branch = "master"diff --git a/main.go b/main.goindex 625856d32..be92f2ab9 100644--- a/main.go+++ b/main.go@@ -13,7 +13,7 @@ import ()var buildtime string-var version = "0.10.0"+var version = "0.11.0-beta"func main() {fmt.Printf("Application is starting...\n")diff --git a/vendor/golang.org/x/oauth2/client_appengine.go b/vendor/golang.org/x/oauth2/client_appengine.godeleted file mode 100644index 8962c49d1..000000000--- a/vendor/golang.org/x/oauth2/client_appengine.go+++ /dev/null@@ -1,25 +0,0 @@-// Copyright 2014 The Go Authors. All rights reserved.-// Use of this source code is governed by a BSD-style-// license that can be found in the LICENSE file.--// +build appengine--// App Engine hooks.--package oauth2--import (- "net/http"-- "golang.org/x/net/context"- "golang.org/x/oauth2/internal"- "google.golang.org/appengine/urlfetch"-)--func init() {- internal.RegisterContextClientFunc(contextClientAppEngine)-}--func contextClientAppEngine(ctx context.Context) (*http.Client, error) {- return urlfetch.Client(ctx), nil-}diff --git a/vendor/golang.org/x/oauth2/clientcredentials/clientcredentials.go b/vendor/golang.org/x/oauth2/clientcredentials/clientcredentials.goindex 53a96b6d6..c4e840d22 100644--- a/vendor/golang.org/x/oauth2/clientcredentials/clientcredentials.go+++ b/vendor/golang.org/x/oauth2/clientcredentials/clientcredentials.go@@ -82,7 +82,9 @@ type tokenSource struct {func (c *tokenSource) Token() (*oauth2.Token, error) {v := url.Values{"grant_type": {"client_credentials"},- "scope": internal.CondVal(strings.Join(c.conf.Scopes, " ")),+ }+ if len(c.conf.Scopes) > 0 {+ v.Set("scope", strings.Join(c.conf.Scopes, " "))}for k, p := range c.conf.EndpointParams {if _, ok := v[k]; ok {@@ -92,6 +94,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{diff --git a/vendor/golang.org/x/oauth2/google/sdk.go b/vendor/golang.org/x/oauth2/google/sdk.goindex bdc18084b..b9660cadd 100644--- a/vendor/golang.org/x/oauth2/google/sdk.go+++ b/vendor/golang.org/x/oauth2/google/sdk.go@@ -5,9 +5,11 @@package googleimport (+ "bufio""encoding/json""errors""fmt"+ "io""net/http""os""os/user"@@ -18,7 +20,6 @@ import ("golang.org/x/net/context""golang.org/x/oauth2"- "golang.org/x/oauth2/internal")type sdkCredentials struct {@@ -76,7 +77,7 @@ func NewSDKConfig(account string) (*SDKConfig, error) {return nil, fmt.Errorf("oauth2/google: failed to load SDK properties: %v", err)}defer f.Close()- ini, err := internal.ParseINI(f)+ ini, err := parseINI(f)if err != nil {return nil, fmt.Errorf("oauth2/google: failed to parse SDK properties %q: %v", propertiesPath, err)}@@ -146,6 +147,34 @@ func (c *SDKConfig) Scopes() []string {return c.conf.Scopes}+func parseINI(ini io.Reader) (map[string]map[string]string, error) {+ result := map[string]map[string]string{+ "": {}, // root section+ }+ scanner := bufio.NewScanner(ini)+ currentSection := ""+ for scanner.Scan() {+ line := strings.TrimSpace(scanner.Text())+ if strings.HasPrefix(line, ";") {+ // comment.+ continue+ }+ if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {+ currentSection = strings.TrimSpace(line[1 : len(line)-1])+ result[currentSection] = map[string]string{}+ continue+ }+ parts := strings.SplitN(line, "=", 2)+ if len(parts) == 2 && parts[0] != "" {+ result[currentSection][strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])+ }+ }+ if err := scanner.Err(); err != nil {+ return nil, fmt.Errorf("error scanning ini: %v", err)+ }+ return result, nil+}+// sdkConfigPath tries to guess where the gcloud config is located.// It can be overridden during tests.var sdkConfigPath = func() (string, error) {diff --git a/vendor/golang.org/x/oauth2/google/sdk_test.go b/vendor/golang.org/x/oauth2/google/sdk_test.goindex 4489bb943..52b8ecada 100644--- a/vendor/golang.org/x/oauth2/google/sdk_test.go+++ b/vendor/golang.org/x/oauth2/google/sdk_test.go@@ -4,7 +4,11 @@package google-import "testing"+import (+ "reflect"+ "strings"+ "testing"+)func TestSDKConfig(t *testing.T) {sdkConfigPath = func() (string, error) {@@ -44,3 +48,60 @@ func TestSDKConfig(t *testing.T) {}}}++func TestParseINI(t *testing.T) {+ tests := []struct {+ ini string+ want map[string]map[string]string+ }{+ {+ `root = toor+[foo]+bar = hop+ini = nin+`,+ map[string]map[string]string{+ "": {"root": "toor"},+ "foo": {"bar": "hop", "ini": "nin"},+ },+ },+ {+ "\t extra \t = whitespace \t\r\n \t [everywhere] \t \r\n here \t = \t there \t \r\n",+ map[string]map[string]string{+ "": {"extra": "whitespace"},+ "everywhere": {"here": "there"},+ },+ },+ {+ `[empty]+[section]+empty=+`,+ map[string]map[string]string{+ "": {},+ "empty": {},+ "section": {"empty": ""},+ },+ },+ {+ `ignore+[invalid+=stuff+;comment=true+`,+ map[string]map[string]string{+ "": {},+ },+ },+ }+ for _, tt := range tests {+ result, err := parseINI(strings.NewReader(tt.ini))+ if err != nil {+ t.Errorf("parseINI(%q) error %v, want: no error", tt.ini, err)+ continue+ }+ if !reflect.DeepEqual(result, tt.want) {+ t.Errorf("parseINI(%q) = %#v, want: %#v", tt.ini, result, tt.want)+ }+ }+}diff --git a/vendor/golang.org/x/oauth2/internal/client_appengine.go b/vendor/golang.org/x/oauth2/internal/client_appengine.gonew file mode 100644index 000000000..743487188--- /dev/null+++ b/vendor/golang.org/x/oauth2/internal/client_appengine.go@@ -0,0 +1,13 @@+// Copyright 2018 The Go Authors. All rights reserved.+// Use of this source code is governed by a BSD-style+// license that can be found in the LICENSE file.++// +build appengine++package internal++import "google.golang.org/appengine/urlfetch"++func init() {+ appengineClientHook = urlfetch.Client+}diff --git a/vendor/golang.org/x/oauth2/internal/doc.go b/vendor/golang.org/x/oauth2/internal/doc.gonew file mode 100644index 000000000..03265e888--- /dev/null+++ b/vendor/golang.org/x/oauth2/internal/doc.go@@ -0,0 +1,6 @@+// Copyright 2017 The Go Authors. All rights reserved.+// Use of this source code is governed by a BSD-style+// license that can be found in the LICENSE file.++// Package internal contains support packages for oauth2 package.+package internaldiff --git a/vendor/golang.org/x/oauth2/internal/oauth2.go b/vendor/golang.org/x/oauth2/internal/oauth2.goindex e31541b39..fc63fcab3 100644--- a/vendor/golang.org/x/oauth2/internal/oauth2.go+++ b/vendor/golang.org/x/oauth2/internal/oauth2.go@@ -2,18 +2,14 @@// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.-// Package internal contains support packages for oauth2 package.package internalimport (- "bufio""crypto/rsa""crypto/x509""encoding/pem""errors""fmt"- "io"- "strings")// ParseKey converts the binary contents of a private key file@@ -39,38 +35,3 @@ func ParseKey(key []byte) (*rsa.PrivateKey, error) {}return parsed, nil}--func ParseINI(ini io.Reader) (map[string]map[string]string, error) {- result := map[string]map[string]string{- "": {}, // root section- }- scanner := bufio.NewScanner(ini)- currentSection := ""- for scanner.Scan() {- line := strings.TrimSpace(scanner.Text())- if strings.HasPrefix(line, ";") {- // comment.- continue- }- if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {- currentSection = strings.TrimSpace(line[1 : len(line)-1])- result[currentSection] = map[string]string{}- continue- }- parts := strings.SplitN(line, "=", 2)- if len(parts) == 2 && parts[0] != "" {- result[currentSection][strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])- }- }- if err := scanner.Err(); err != nil {- return nil, fmt.Errorf("error scanning ini: %v", err)- }- return result, nil-}--func CondVal(v string) []string {- if v == "" {- return nil- }- return []string{v}-}diff --git a/vendor/golang.org/x/oauth2/internal/oauth2_test.go b/vendor/golang.org/x/oauth2/internal/oauth2_test.godeleted file mode 100644index 0aafc7f43..000000000--- a/vendor/golang.org/x/oauth2/internal/oauth2_test.go+++ /dev/null@@ -1,62 +0,0 @@-// Copyright 2014 The Go Authors. All rights reserved.-// Use of this source code is governed by a BSD-style-// license that can be found in the LICENSE file.--// Package internal contains support packages for oauth2 package.-package internal--import (- "reflect"- "strings"- "testing"-)--func TestParseINI(t *testing.T) {- tests := []struct {- ini string- want map[string]map[string]string- }{- {- `root = toor-[foo]-bar = hop-ini = nin-`,- map[string]map[string]string{- "": {"root": "toor"},- "foo": {"bar": "hop", "ini": "nin"},- },- },- {- `[empty]-[section]-empty=-`,- map[string]map[string]string{- "": {},- "empty": {},- "section": {"empty": ""},- },- },- {- `ignore-[invalid-=stuff-;comment=true-`,- map[string]map[string]string{- "": {},- },- },- }- for _, tt := range tests {- result, err := ParseINI(strings.NewReader(tt.ini))- if err != nil {- t.Errorf("ParseINI(%q) error %v, want: no error", tt.ini, err)- continue- }- if !reflect.DeepEqual(result, tt.want) {- t.Errorf("ParseINI(%q) = %#v, want: %#v", tt.ini, result, tt.want)- }- }-}diff --git a/vendor/golang.org/x/oauth2/internal/token.go b/vendor/golang.org/x/oauth2/internal/token.goindex 53ec23cee..ce3f27e02 100644--- a/vendor/golang.org/x/oauth2/internal/token.go+++ b/vendor/golang.org/x/oauth2/internal/token.go@@ -2,11 +2,11 @@// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.-// Package internal contains support packages for oauth2 package.package internalimport ("encoding/json"+ "errors""fmt""io""io/ioutil"@@ -21,7 +21,7 @@ import ("golang.org/x/net/context/ctxhttp")-// Token represents the crendentials used to authorize+// Token represents the credentials used to authorize// the requests to access protected resources on the OAuth 2.0// provider's backend.//@@ -103,10 +103,11 @@ var brokenAuthHeaderProviders = []string{"https://api.twitch.tv/","https://app.box.com/","https://connect.stripe.com/",- "https://graph.facebook.com", // see https://github.com/golang/oauth2/issues/214+ "https://login.mailchimp.com/","https://login.microsoftonline.com/","https://login.salesforce.com/","https://login.windows.net",+ "https://login.live.com/","https://oauth.sandbox.trainingpeaks.com/","https://oauth.trainingpeaks.com/","https://oauth.vk.com/",@@ -123,10 +124,13 @@ var brokenAuthHeaderProviders = []string{"https://api.patreon.com/","https://sandbox.codeswholesale.com/oauth/token","https://api.sipgate.com/v1/authorization/oauth",+ "https://api.medium.com/v1/tokens",+ "https://log.finalsurge.com/oauth/token",}// brokenAuthHeaderDomains lists broken providers that issue dynamic endpoints.var brokenAuthHeaderDomains = []string{+ ".auth0.com",".force.com",".myshopify.com",".okta.com",@@ -169,10 +173,6 @@ func providerAuthHeaderWorks(tokenURL string) bool {}func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string, v url.Values) (*Token, error) {- hc, err := ContextClient(ctx)- if err != nil {- return nil, err- }bustedAuth := !providerAuthHeaderWorks(tokenURL)if bustedAuth {if clientID != "" {@@ -190,7 +190,7 @@ func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string,if !bustedAuth {req.SetBasicAuth(url.QueryEscape(clientID), url.QueryEscape(clientSecret))}- r, err := ctxhttp.Do(ctx, hc, req)+ r, err := ctxhttp.Do(ctx, ContextClient(ctx), req)if err != nil {return nil, err}@@ -200,7 +200,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, &RetrieveError{+ Response: r,+ Body: body,+ }}var token *Token@@ -247,5 +250,17 @@ func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string,if token.RefreshToken == "" {token.RefreshToken = v.Get("refresh_token")}+ if token.AccessToken == "" {+ return token, errors.New("oauth2: server response missing access_token")+ }return token, nil}++type RetrieveError struct {+ Response *http.Response+ Body []byte+}++func (r *RetrieveError) Error() string {+ return fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", r.Response.Status, r.Body)+}diff --git a/vendor/golang.org/x/oauth2/internal/token_test.go b/vendor/golang.org/x/oauth2/internal/token_test.goindex c19a462cc..7b52e511f 100644--- a/vendor/golang.org/x/oauth2/internal/token_test.go+++ b/vendor/golang.org/x/oauth2/internal/token_test.go@@ -2,11 +2,11 @@// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.-// Package internal contains support packages for oauth2 package.package internalimport ("fmt"+ "io""net/http""net/http/httptest""net/url"@@ -33,6 +33,8 @@ func TestRetrieveTokenBustedNoSecret(t *testing.T) {if got, want := r.FormValue("client_secret"), ""; got != want {t.Errorf("client_secret = %q; want empty", got)}+ w.Header().Set("Content-Type", "application/json")+ io.WriteString(w, `{"access_token": "ACCESS_TOKEN", "token_type": "bearer"}`)}))defer ts.Close()@@ -83,7 +85,10 @@ func TestProviderAuthHeaderWorksDomain(t *testing.T) {func TestRetrieveTokenWithContexts(t *testing.T) {const clientID = "client-id"- ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.Header().Set("Content-Type", "application/json")+ io.WriteString(w, `{"access_token": "ACCESS_TOKEN", "token_type": "bearer"}`)+ }))defer ts.Close()_, err := RetrieveToken(context.Background(), clientID, "", ts.URL, url.Values{})@@ -91,14 +96,16 @@ func TestRetrieveTokenWithContexts(t *testing.T) {t.Errorf("RetrieveToken (with background context) = %v; want no error", err)}- ctx, cancelfunc := context.WithCancel(context.Background())-+ retrieved := make(chan struct{})cancellingts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- cancelfunc()+ <-retrieved}))defer cancellingts.Close()+ ctx, cancel := context.WithCancel(context.Background())+ cancel()_, err = RetrieveToken(ctx, clientID, "", cancellingts.URL, url.Values{})+ close(retrieved)if err == nil {t.Errorf("RetrieveToken (with cancelled context) = nil; want error")}diff --git a/vendor/golang.org/x/oauth2/internal/transport.go b/vendor/golang.org/x/oauth2/internal/transport.goindex f1f173e34..d16f9ae1f 100644--- a/vendor/golang.org/x/oauth2/internal/transport.go+++ b/vendor/golang.org/x/oauth2/internal/transport.go@@ -2,7 +2,6 @@// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.-// Package internal contains support packages for oauth2 package.package internalimport (@@ -20,50 +19,16 @@ var HTTPClient ContextKey// because nobody else can create a ContextKey, being unexported.type ContextKey struct{}-// ContextClientFunc is a func which tries to return an *http.Client-// given a Context value. If it returns an error, the search stops-// with that error. If it returns (nil, nil), the search continues-// down the list of registered funcs.-type ContextClientFunc func(context.Context) (*http.Client, error)+var appengineClientHook func(context.Context) *http.Client-var contextClientFuncs []ContextClientFunc--func RegisterContextClientFunc(fn ContextClientFunc) {- contextClientFuncs = append(contextClientFuncs, fn)-}--func ContextClient(ctx context.Context) (*http.Client, error) {+func ContextClient(ctx context.Context) *http.Client {if ctx != nil {if hc, ok := ctx.Value(HTTPClient).(*http.Client); ok {- return hc, nil+ return hc}}- for _, fn := range contextClientFuncs {- c, err := fn(ctx)- if err != nil {- return nil, err- }- if c != nil {- return c, nil- }+ if appengineClientHook != nil {+ return appengineClientHook(ctx)}- return http.DefaultClient, nil-}--func ContextTransport(ctx context.Context) http.RoundTripper {- hc, err := ContextClient(ctx)- // This is a rare error case (somebody using nil on App Engine).- if err != nil {- return ErrorTransport{err}- }- return hc.Transport-}--// ErrorTransport returns the specified error on RoundTrip.-// This RoundTripper should be used in rare error cases where-// error handling can be postponed to response handling time.-type ErrorTransport struct{ Err error }--func (t ErrorTransport) RoundTrip(*http.Request) (*http.Response, error) {- return nil, t.Err+ return http.DefaultClient}diff --git a/vendor/golang.org/x/oauth2/internal/transport_test.go b/vendor/golang.org/x/oauth2/internal/transport_test.godeleted file mode 100644index 8772ec5c4..000000000--- a/vendor/golang.org/x/oauth2/internal/transport_test.go+++ /dev/null@@ -1,38 +0,0 @@-// Copyright 2015 The Go Authors. All rights reserved.-// Use of this source code is governed by a BSD-style-// license that can be found in the LICENSE file.--package internal--import (- "net/http"- "testing"-- "golang.org/x/net/context"-)--func TestContextClient(t *testing.T) {- rc := &http.Client{}- RegisterContextClientFunc(func(context.Context) (*http.Client, error) {- return rc, nil- })-- c := &http.Client{}- ctx := context.WithValue(context.Background(), HTTPClient, c)-- hc, err := ContextClient(ctx)- if err != nil {- t.Fatalf("want valid client; got err = %v", err)- }- if hc != c {- t.Fatalf("want context client = %p; got = %p", c, hc)- }-- hc, err = ContextClient(context.TODO())- if err != nil {- t.Fatalf("want valid client; got err = %v", err)- }- if hc != rc {- t.Fatalf("want registered client = %p; got = %p", c, hc)- }-}diff --git a/vendor/golang.org/x/oauth2/jwt/jwt.go b/vendor/golang.org/x/oauth2/jwt/jwt.goindex e016db421..e08f31595 100644--- a/vendor/golang.org/x/oauth2/jwt/jwt.go+++ b/vendor/golang.org/x/oauth2/jwt/jwt.go@@ -124,7 +124,10 @@ func (js jwtSource) Token() (*oauth2.Token, error) {return nil, fmt.Errorf("oauth2: cannot fetch token: %v", err)}if c := resp.StatusCode; c < 200 || c > 299 {- return nil, fmt.Errorf("oauth2: cannot fetch token: %v\nResponse: %s", resp.Status, body)+ return nil, &oauth2.RetrieveError{+ Response: resp,+ Body: body,+ }}// tokenRes is the JSON response body.var tokenRes struct {diff --git a/vendor/golang.org/x/oauth2/jwt/jwt_test.go b/vendor/golang.org/x/oauth2/jwt/jwt_test.goindex 9f82c71c1..1fbb9aa7d 100644--- a/vendor/golang.org/x/oauth2/jwt/jwt_test.go+++ b/vendor/golang.org/x/oauth2/jwt/jwt_test.go@@ -8,11 +8,13 @@ import ("context""encoding/base64""encoding/json"+ "fmt""net/http""net/http/httptest""strings""testing"+ "golang.org/x/oauth2""golang.org/x/oauth2/jws")@@ -188,3 +190,32 @@ func TestJWTFetch_Assertion(t *testing.T) {t.Errorf("access token header = %q; want %q", got, want)}}++func TestTokenRetrieveError(t *testing.T) {+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.Header().Set("Content-type", "application/json")+ w.WriteHeader(http.StatusBadRequest)+ w.Write([]byte(`{"error": "invalid_grant"}`))+ }))+ defer ts.Close()++ conf := &Config{+ Email: "[email protected]",+ PrivateKey: dummyPrivateKey,+ TokenURL: ts.URL,+ }++ _, err := conf.TokenSource(context.Background()).Token()+ if err == nil {+ t.Fatalf("got no error, expected one")+ }+ _, ok := err.(*oauth2.RetrieveError)+ if !ok {+ t.Fatalf("got %T error, expected *RetrieveError", err)+ }+ // Test error string for backwards compatibility+ expected := fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", "400 Bad Request", `{"error": "invalid_grant"}`)+ if errStr := err.Error(); errStr != expected {+ t.Fatalf("got %#v, expected %#v", errStr, expected)+ }+}diff --git a/vendor/golang.org/x/oauth2/mailchimp/mailchimp.go b/vendor/golang.org/x/oauth2/mailchimp/mailchimp.gonew file mode 100644index 000000000..647787ec6--- /dev/null+++ b/vendor/golang.org/x/oauth2/mailchimp/mailchimp.go@@ -0,0 +1,17 @@+// Copyright 2018 The Go Authors. All rights reserved.+// Use of this source code is governed by a BSD-style+// license that can be found in the LICENSE file.++// Package mailchimp provides constants for using OAuth2 to access MailChimp.+package mailchimp // import "golang.org/x/oauth2/mailchimp"++import (+ "golang.org/x/oauth2"+)++// Endpoint is MailChimp's OAuth 2.0 endpoint.+// See http://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/+var Endpoint = oauth2.Endpoint{+ AuthURL: "https://login.mailchimp.com/oauth2/authorize",+ TokenURL: "https://login.mailchimp.com/oauth2/token",+}diff --git a/vendor/golang.org/x/oauth2/mailru/mailru.go b/vendor/golang.org/x/oauth2/mailru/mailru.gonew file mode 100644index 000000000..dddd9dd0f--- /dev/null+++ b/vendor/golang.org/x/oauth2/mailru/mailru.go@@ -0,0 +1,16 @@+// Copyright 2017 The Go Authors. All rights reserved.+// Use of this source code is governed by a BSD-style+// license that can be found in the LICENSE file.++// Package mailru provides constants for using OAuth2 to access Mail.Ru.+package mailru // import "golang.org/x/oauth2/mailru"++import (+ "golang.org/x/oauth2"+)++// Endpoint is Mail.Ru's OAuth 2.0 endpoint.+var Endpoint = oauth2.Endpoint{+ AuthURL: "https://o2.mail.ru/login",+ TokenURL: "https://o2.mail.ru/token",+}diff --git a/vendor/golang.org/x/oauth2/microsoft/microsoft.go b/vendor/golang.org/x/oauth2/microsoft/microsoft.goindex f21b3985b..3ffbc57a6 100644--- a/vendor/golang.org/x/oauth2/microsoft/microsoft.go+++ b/vendor/golang.org/x/oauth2/microsoft/microsoft.go@@ -14,3 +14,18 @@ var LiveConnectEndpoint = oauth2.Endpoint{AuthURL: "https://login.live.com/oauth20_authorize.srf",TokenURL: "https://login.live.com/oauth20_token.srf",}++// AzureADEndpoint returns a new oauth2.Endpoint for the given tenant at Azure Active Directory.+// If tenant is empty, it uses the tenant called `common`.+//+// For more information see:+// https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols#endpoints+func AzureADEndpoint(tenant string) oauth2.Endpoint {+ if tenant == "" {+ tenant = "common"+ }+ return oauth2.Endpoint{+ AuthURL: "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/authorize",+ TokenURL: "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token",+ }+}diff --git a/vendor/golang.org/x/oauth2/oauth2.go b/vendor/golang.org/x/oauth2/oauth2.goindex 4bafe873d..a047a5f98 100644--- a/vendor/golang.org/x/oauth2/oauth2.go+++ b/vendor/golang.org/x/oauth2/oauth2.go@@ -117,7 +117,7 @@ func SetAuthURLParam(key, value string) AuthCodeOption {// that asks for permissions for the required scopes explicitly.//// State is a token to protect the user from CSRF attacks. You must-// always provide a non-zero string and validate that it matches the+// always provide a non-empty string and validate that it matches the// the state query parameter on your redirect callback.// See http://tools.ietf.org/html/rfc6749#section-10.12 for more info.//@@ -129,9 +129,16 @@ func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {v := url.Values{"response_type": {"code"},"client_id": {c.ClientID},- "redirect_uri": internal.CondVal(c.RedirectURL),- "scope": internal.CondVal(strings.Join(c.Scopes, " ")),- "state": internal.CondVal(state),+ }+ if c.RedirectURL != "" {+ v.Set("redirect_uri", c.RedirectURL)+ }+ if len(c.Scopes) > 0 {+ v.Set("scope", strings.Join(c.Scopes, " "))+ }+ if state != "" {+ // TODO(light): Docs say never to omit state; don't allow empty.+ v.Set("state", state)}for _, opt := range opts {opt.setValue(v)@@ -157,12 +164,15 @@ func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {// The HTTP client to use is derived from the context.// If nil, http.DefaultClient is used.func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string) (*Token, error) {- return retrieveToken(ctx, c, url.Values{+ v := url.Values{"grant_type": {"password"},"username": {username},"password": {password},- "scope": internal.CondVal(strings.Join(c.Scopes, " ")),- })+ }+ if len(c.Scopes) > 0 {+ v.Set("scope", strings.Join(c.Scopes, " "))+ }+ return retrieveToken(ctx, c, v)}// Exchange converts an authorization code into a token.@@ -176,11 +186,14 @@ func (c *Config) PasswordCredentialsToken(ctx context.Context, username, passwor// The code will be in the *http.Request.FormValue("code"). Before// calling Exchange, be sure to validate FormValue("state").func (c *Config) Exchange(ctx context.Context, code string) (*Token, error) {- return retrieveToken(ctx, c, url.Values{- "grant_type": {"authorization_code"},- "code": {code},- "redirect_uri": internal.CondVal(c.RedirectURL),- })+ v := url.Values{+ "grant_type": {"authorization_code"},+ "code": {code},+ }+ if c.RedirectURL != "" {+ v.Set("redirect_uri", c.RedirectURL)+ }+ return retrieveToken(ctx, c, v)}// Client returns an HTTP client using the provided token.@@ -300,15 +313,11 @@ var HTTPClient internal.ContextKey// packages.func NewClient(ctx context.Context, src TokenSource) *http.Client {if src == nil {- c, err := internal.ContextClient(ctx)- if err != nil {- return &http.Client{Transport: internal.ErrorTransport{Err: err}}- }- return c+ return internal.ContextClient(ctx)}return &http.Client{Transport: &Transport{- Base: internal.ContextTransport(ctx),+ Base: internal.ContextClient(ctx).Transport,Source: ReuseTokenSource(nil, src),},}diff --git a/vendor/golang.org/x/oauth2/oauth2_test.go b/vendor/golang.org/x/oauth2/oauth2_test.goindex 09293ede1..847160f91 100644--- a/vendor/golang.org/x/oauth2/oauth2_test.go+++ b/vendor/golang.org/x/oauth2/oauth2_test.go@@ -278,12 +278,9 @@ func TestExchangeRequest_BadResponse(t *testing.T) {}))defer ts.Close()conf := newConf(ts.URL)- tok, err := conf.Exchange(context.Background(), "code")- if err != nil {- t.Fatal(err)- }- if tok.AccessToken != "" {- t.Errorf("Unexpected access token, %#v.", tok.AccessToken)+ _, err := conf.Exchange(context.Background(), "code")+ if err == nil {+ t.Error("expected error from missing access_token")}}@@ -296,7 +293,7 @@ func TestExchangeRequest_BadResponseType(t *testing.T) {conf := newConf(ts.URL)_, err := conf.Exchange(context.Background(), "exchange-code")if err == nil {- t.Error("expected error from invalid access_token type")+ t.Error("expected error from non-string access_token")}}@@ -419,6 +416,32 @@ func TestFetchWithNoRefreshToken(t *testing.T) {}}+func TestTokenRetrieveError(t *testing.T) {+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.URL.String() != "/token" {+ t.Errorf("Unexpected token refresh request URL, %v is found.", r.URL)+ }+ w.Header().Set("Content-type", "application/json")+ w.WriteHeader(http.StatusBadRequest)+ w.Write([]byte(`{"error": "invalid_grant"}`))+ }))+ defer ts.Close()+ conf := newConf(ts.URL)+ _, err := conf.Exchange(context.Background(), "exchange-code")+ if err == nil {+ t.Fatalf("got no error, expected one")+ }+ _, ok := err.(*RetrieveError)+ if !ok {+ t.Fatalf("got %T error, expected *RetrieveError", err)+ }+ // Test error string for backwards compatibility+ expected := fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", "400 Bad Request", `{"error": "invalid_grant"}`)+ if errStr := err.Error(); errStr != expected {+ t.Fatalf("got %#v, expected %#v", errStr, expected)+ }+}+func TestRefreshToken_RefreshTokenReplacement(t *testing.T) {ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {w.Header().Set("Content-Type", "application/json")@@ -427,18 +450,14 @@ func TestRefreshToken_RefreshTokenReplacement(t *testing.T) {}))defer ts.Close()conf := newConf(ts.URL)- tkr := &tokenRefresher{- conf: conf,- ctx: context.Background(),- refreshToken: "OLD_REFRESH_TOKEN",- }+ tkr := conf.TokenSource(context.Background(), &Token{RefreshToken: "OLD_REFRESH_TOKEN"})tk, err := tkr.Token()if err != nil {t.Errorf("got err = %v; want none", err)return}- if tk.RefreshToken != tkr.refreshToken {- t.Errorf("tokenRefresher.refresh_token = %q; want %q", tkr.refreshToken, tk.RefreshToken)+ if want := "NEW_REFRESH_TOKEN"; tk.RefreshToken != want {+ t.Errorf("RefreshToken = %q; want %q", tk.RefreshToken, want)}}@@ -451,17 +470,13 @@ func TestRefreshToken_RefreshTokenPreservation(t *testing.T) {defer ts.Close()conf := newConf(ts.URL)const oldRefreshToken = "OLD_REFRESH_TOKEN"- tkr := &tokenRefresher{- conf: conf,- ctx: context.Background(),- refreshToken: oldRefreshToken,- }- _, err := tkr.Token()+ tkr := conf.TokenSource(context.Background(), &Token{RefreshToken: oldRefreshToken})+ tk, err := tkr.Token()if err != nil {t.Fatalf("got err = %v; want none", err)}- if tkr.refreshToken != oldRefreshToken {- t.Errorf("tokenRefresher.refreshToken = %q; want %q", tkr.refreshToken, oldRefreshToken)+ if tk.RefreshToken != oldRefreshToken {+ t.Errorf("RefreshToken = %q; want %q", tk.RefreshToken, oldRefreshToken)}}diff --git a/vendor/golang.org/x/oauth2/spotify/spotify.go b/vendor/golang.org/x/oauth2/spotify/spotify.gonew file mode 100644index 000000000..c75416c00--- /dev/null+++ b/vendor/golang.org/x/oauth2/spotify/spotify.go@@ -0,0 +1,16 @@+// Copyright 2018 The Go Authors. All rights reserved.+// Use of this source code is governed by a BSD-style+// license that can be found in the LICENSE file.++// Package spotify provides constants for using OAuth2 to access Spotify.+package spotify // import "golang.org/x/oauth2/spotify"++import (+ "golang.org/x/oauth2"+)++// Endpoint is Spotify's OAuth 2.0 endpoint.+var Endpoint = oauth2.Endpoint{+ AuthURL: "https://accounts.spotify.com/authorize",+ TokenURL: "https://accounts.spotify.com/api/token",+}diff --git a/vendor/golang.org/x/oauth2/token.go b/vendor/golang.org/x/oauth2/token.goindex 7a3167f15..34db8cdc8 100644--- a/vendor/golang.org/x/oauth2/token.go+++ b/vendor/golang.org/x/oauth2/token.go@@ -5,6 +5,7 @@package oauth2import (+ "fmt""net/http""net/url""strconv"@@ -20,7 +21,7 @@ import (// expirations due to client-server time mismatches.const expiryDelta = 10 * time.Second-// Token represents the crendentials used to authorize+// Token represents the credentials used to authorize// the requests to access protected resources on the OAuth 2.0// provider's backend.//@@ -123,7 +124,7 @@ func (t *Token) expired() bool {if t.Expiry.IsZero() {return false}- return t.Expiry.Add(-expiryDelta).Before(time.Now())+ return t.Expiry.Round(0).Add(-expiryDelta).Before(time.Now())}// Valid reports whether t is non-nil, has an AccessToken, and is not expired.@@ -152,7 +153,23 @@ func tokenFromInternal(t *internal.Token) *Token {func retrieveToken(ctx context.Context, c *Config, v url.Values) (*Token, error) {tk, err := internal.RetrieveToken(ctx, c.ClientID, c.ClientSecret, c.Endpoint.TokenURL, v)if err != nil {+ if rErr, ok := err.(*internal.RetrieveError); ok {+ return nil, (*RetrieveError)(rErr)+ }return nil, err}return tokenFromInternal(tk), nil}++// RetrieveError is the error returned when the token endpoint returns a+// non-2XX HTTP status code.+type RetrieveError struct {+ Response *http.Response+ // Body is the body that was consumed by reading Response.Body.+ // It may be truncated.+ Body []byte+}++func (r *RetrieveError) Error() string {+ return fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", r.Response.Status, r.Body)+}diff --git a/vendor/golang.org/x/oauth2/twitch/twitch.go b/vendor/golang.org/x/oauth2/twitch/twitch.gonew file mode 100644index 000000000..8c5f06aae--- /dev/null+++ b/vendor/golang.org/x/oauth2/twitch/twitch.go@@ -0,0 +1,19 @@+// Copyright 2017 The Go Authors. All rights reserved.+// Use of this source code is governed by a BSD-style+// license that can be found in the LICENSE file.++// Package twitch provides constants for using OAuth2 to access Twitch.+package twitch // import "golang.org/x/oauth2/twitch"++import (+ "golang.org/x/oauth2"+)++// Endpoint is Twitch's OAuth 2.0 endpoint.+//+// For more information see:+// https://dev.twitch.tv/docs/authentication+var Endpoint = oauth2.Endpoint{+ AuthURL: "https://api.twitch.tv/kraken/oauth2/authorize",+ TokenURL: "https://api.twitch.tv/kraken/oauth2/token",+}diff --git a/vendor/golang.org/x/oauth2/yahoo/yahoo.go b/vendor/golang.org/x/oauth2/yahoo/yahoo.gonew file mode 100644index 000000000..9fa78a23c--- /dev/null+++ b/vendor/golang.org/x/oauth2/yahoo/yahoo.go@@ -0,0 +1,17 @@+// Copyright 2017 The Go Authors. All rights reserved.+// Use of this source code is governed by a BSD-style+// license that can be found in the LICENSE file.++// Package yahoo provides constants for using OAuth2 to access Yahoo.+package yahoo // import "golang.org/x/oauth2/yahoo"++import (+ "golang.org/x/oauth2"+)++// Endpoint is Yahoo's OAuth 2.0 endpoint.+// See https://developer.yahoo.com/oauth2/guide/+var Endpoint = oauth2.Endpoint{+ AuthURL: "https://api.login.yahoo.com/oauth2/request_auth",+ TokenURL: "https://api.login.yahoo.com/oauth2/get_token",+}