diff --git a/.gitignore b/.gitignore index 4f39cfc63..5ce409a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ node_modules/ dist/ generated/ .vendor/ +vendor *.swp .vscode/launch.json .vscode/settings.json diff --git a/go.sum b/go.sum index 75497ee0e..625cfac48 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk= diff --git a/gothic/gothic.go b/gothic/gothic.go index 0c32caff1..b895a12d1 100644 --- a/gothic/gothic.go +++ b/gothic/gothic.go @@ -16,14 +16,11 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" "strings" - "github.com/go-chi/chi/v5" - "github.com/gorilla/mux" "github.com/gorilla/sessions" "github.com/markbates/goth" ) @@ -254,60 +251,6 @@ func Logout(res http.ResponseWriter, req *http.Request) error { return nil } -// GetProviderName is a function used to get the name of a provider -// for a given request. By default, this provider is fetched from -// the URL query string. If you provide it in a different way, -// assign your own function to this variable that returns the provider -// name for your request. -var GetProviderName = getProviderName - -func getProviderName(req *http.Request) (string, error) { - - // try to get it from the url param "provider" - if p := req.URL.Query().Get("provider"); p != "" { - return p, nil - } - - // try to get it from the url param ":provider" - if p := req.URL.Query().Get(":provider"); p != "" { - return p, nil - } - - // try to get it from the context's value of "provider" key - if p, ok := mux.Vars(req)["provider"]; ok { - return p, nil - } - - // try to get it from the go-context's value of "provider" key - if p, ok := req.Context().Value("provider").(string); ok { - return p, nil - } - - // try to get it from the url param "provider", when req is routed through 'chi' - if p := chi.URLParam(req, "provider"); p != "" { - return p, nil - } - - // try to get it from the go-context's value of providerContextKey key - if p, ok := req.Context().Value(ProviderParamKey).(string); ok { - return p, nil - } - - // As a fallback, loop over the used providers, if we already have a valid session for any provider (ie. user has already begun authentication with a provider), then return that provider name - providers := goth.GetProviders() - session, _ := Store.Get(req, SessionName) - for _, provider := range providers { - p := provider.Name() - value := session.Values[p] - if _, ok := value.(string); ok { - return p, nil - } - } - - // if not found then return an empty string with the corresponding error - return "", errors.New("you must select a provider") -} - // GetContextWithProvider returns a new request context containing the provider func GetContextWithProvider(req *http.Request, provider string) *http.Request { return req.WithContext(context.WithValue(req.Context(), ProviderParamKey, provider)) @@ -347,7 +290,7 @@ func getSessionValue(session *sessions.Session, key string) (string, error) { if err != nil { return "", err } - s, err := ioutil.ReadAll(r) + s, err := io.ReadAll(r) if err != nil { return "", err } diff --git a/gothic/gothic_test.go b/gothic/gothic_test.go index bb0254a0a..22c8448a2 100644 --- a/gothic/gothic_test.go +++ b/gothic/gothic_test.go @@ -5,7 +5,7 @@ import ( "compress/gzip" "fmt" "html" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -283,7 +283,7 @@ func ungzipString(value string) string { if err != nil { return "err" } - s, err := ioutil.ReadAll(r) + s, err := io.ReadAll(r) if err != nil { return "err" } diff --git a/gothic/provider.go b/gothic/provider.go new file mode 100644 index 000000000..60bc1eb11 --- /dev/null +++ b/gothic/provider.go @@ -0,0 +1,71 @@ +//go:build go1.22 +// +build go1.22 + +package gothic + +import ( + "errors" + "net/http" + + "github.com/go-chi/chi/v5" + "github.com/gorilla/mux" + "github.com/markbates/goth" +) + +// GetProviderName is a function used to get the name of a provider +// for a given request. By default, this provider is fetched from +// the URL query string. If you provide it in a different way, +// assign your own function to this variable that returns the provider +// name for your request. +var GetProviderName = getProviderName + +func getProviderName(req *http.Request) (string, error) { + // try to get it from the url param "provider" + if p := req.URL.Query().Get("provider"); p != "" { + return p, nil + } + + // try to get it from the url param ":provider" + if p := req.URL.Query().Get(":provider"); p != "" { + return p, nil + } + + // try to get it from the context's value of "provider" key + if p, ok := mux.Vars(req)["provider"]; ok { + return p, nil + } + + // try to get it from the go-context's value of "provider" key + if p, ok := req.Context().Value("provider").(string); ok { + return p, nil + } + + // try to get it from the url param "provider", when req is routed through 'chi' + if p := chi.URLParam(req, "provider"); p != "" { + return p, nil + } + + // try to get it from the route param for go >= 1.22 + if p := req.PathValue("provider"); p != "" { + return p, nil + } + + // try to get it from the go-context's value of providerContextKey key + if p, ok := req.Context().Value(ProviderParamKey).(string); ok { + return p, nil + } + + // As a fallback, loop over the used providers, if we already have a valid session for any provider (ie. user has already begun authentication with a provider), then return that provider name + providers := goth.GetProviders() + session, _ := Store.Get(req, SessionName) + for _, provider := range providers { + p := provider.Name() + value := session.Values[p] + if _, ok := value.(string); ok { + return p, nil + } + } + + // if not found then return an empty string with the corresponding error + return "", errors.New("you must select a provider") +} diff --git a/gothic/provider_legacy.go b/gothic/provider_legacy.go new file mode 100644 index 000000000..74cfcffa7 --- /dev/null +++ b/gothic/provider_legacy.go @@ -0,0 +1,66 @@ +//go:build !go1.22 +// +build !go1.22 + +package gothic + +import ( + "errors" + "net/http" + + "github.com/go-chi/chi/v5" + "github.com/gorilla/mux" + "github.com/markbates/goth" +) + +// GetProviderName is a function used to get the name of a provider +// for a given request. By default, this provider is fetched from +// the URL query string. If you provide it in a different way, +// assign your own function to this variable that returns the provider +// name for your request. +var GetProviderName = getProviderName + +func getProviderName(req *http.Request) (string, error) { + // try to get it from the url param "provider" + if p := req.URL.Query().Get("provider"); p != "" { + return p, nil + } + + // try to get it from the url param ":provider" + if p := req.URL.Query().Get(":provider"); p != "" { + return p, nil + } + + // try to get it from the context's value of "provider" key + if p, ok := mux.Vars(req)["provider"]; ok { + return p, nil + } + + // try to get it from the go-context's value of "provider" key + if p, ok := req.Context().Value("provider").(string); ok { + return p, nil + } + + // try to get it from the url param "provider", when req is routed through 'chi' + if p := chi.URLParam(req, "provider"); p != "" { + return p, nil + } + + // try to get it from the go-context's value of providerContextKey key + if p, ok := req.Context().Value(ProviderParamKey).(string); ok { + return p, nil + } + + // As a fallback, loop over the used providers, if we already have a valid session for any provider (ie. user has already begun authentication with a provider), then return that provider name + providers := goth.GetProviders() + session, _ := Store.Get(req, SessionName) + for _, provider := range providers { + p := provider.Name() + value := session.Values[p] + if _, ok := value.(string); ok { + return p, nil + } + } + + // if not found then return an empty string with the corresponding error + return "", errors.New("you must select a provider") +} diff --git a/gothic/provider_test.go b/gothic/provider_test.go new file mode 100644 index 000000000..bf2b456f3 --- /dev/null +++ b/gothic/provider_test.go @@ -0,0 +1,47 @@ +//go:build go1.22 +// +build go1.22 + +package gothic_test + +import ( + "net/http" + "net/http/httptest" + "net/url" + "testing" + + "github.com/markbates/goth/gothic" + "github.com/stretchr/testify/assert" +) + +func Test_GetAuthURL122(t *testing.T) { + a := assert.New(t) + + res := httptest.NewRecorder() + req, err := http.NewRequest("GET", "/auth", nil) + a.NoError(err) + req.SetPathValue("provider", "faux") + + u, err := gothic.GetAuthURL(res, req) + a.NoError(err) + + // Check that we get the correct auth URL with a state parameter + parsed, err := url.Parse(u) + a.NoError(err) + a.Equal("http", parsed.Scheme) + a.Equal("example.com", parsed.Host) + q := parsed.Query() + a.Contains(q, "client_id") + a.Equal("code", q.Get("response_type")) + a.NotZero(q, "state") + + // Check that if we run GetAuthURL on another request, that request's + // auth URL has a different state from the previous one. + req2, err := http.NewRequest("GET", "/auth?provider=faux", nil) + a.NoError(err) + req2.SetPathValue("provider", "faux") + url2, err := gothic.GetAuthURL(httptest.NewRecorder(), req2) + a.NoError(err) + parsed2, err := url.Parse(url2) + a.NoError(err) + a.NotEqual(parsed.Query().Get("state"), parsed2.Query().Get("state")) +} diff --git a/providers/amazon/amazon.go b/providers/amazon/amazon.go index 7061e4d7a..5a0b175cb 100644 --- a/providers/amazon/amazon.go +++ b/providers/amazon/amazon.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" @@ -95,7 +94,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/azureadv2/azureadv2.go b/providers/azureadv2/azureadv2.go index 523f79cce..e76419f80 100644 --- a/providers/azureadv2/azureadv2.go +++ b/providers/azureadv2/azureadv2.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -199,7 +198,7 @@ func userFromReader(r io.Reader, user *goth.User) error { UserPrincipalName string `json:"userPrincipalName"` // The user's principal name. }{} - userBytes, err := ioutil.ReadAll(r) + userBytes, err := io.ReadAll(r) if err != nil { return err } diff --git a/providers/battlenet/battlenet.go b/providers/battlenet/battlenet.go index 3a52b47e7..47abdaca8 100644 --- a/providers/battlenet/battlenet.go +++ b/providers/battlenet/battlenet.go @@ -6,7 +6,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/markbates/goth" @@ -103,7 +103,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/bitbucket/bitbucket.go b/providers/bitbucket/bitbucket.go index 06f2c9607..7c27a913d 100644 --- a/providers/bitbucket/bitbucket.go +++ b/providers/bitbucket/bitbucket.go @@ -5,7 +5,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/markbates/goth" @@ -134,7 +134,7 @@ func (p *Provider) getUserInfo(user *goth.User, sess *Session) error { return fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return err } diff --git a/providers/bitly/bitly.go b/providers/bitly/bitly.go index f302d5fe4..fc1b122c0 100644 --- a/providers/bitly/bitly.go +++ b/providers/bitly/bitly.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -97,7 +96,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { return u, err } diff --git a/providers/classlink/provider.go b/providers/classlink/provider.go index a64a67cae..1dc683689 100644 --- a/providers/classlink/provider.go +++ b/providers/classlink/provider.go @@ -4,7 +4,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "github.com/markbates/goth" @@ -102,7 +102,7 @@ func (p Provider) FetchUser(session goth.Session) (goth.User, error) { defer resp.Body.Close() - bytes, err := ioutil.ReadAll(resp.Body) + bytes, err := io.ReadAll(resp.Body) if err != nil { return user, err } diff --git a/providers/cloudfoundry/cf.go b/providers/cloudfoundry/cf.go index 31eb63f2e..5c06763c8 100644 --- a/providers/cloudfoundry/cf.go +++ b/providers/cloudfoundry/cf.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "strings" @@ -104,7 +103,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode) } - bits, err := ioutil.ReadAll(resp.Body) + bits, err := io.ReadAll(resp.Body) if err != nil { return user, err } diff --git a/providers/cognito/cognito.go b/providers/cognito/cognito.go index ff4bee58d..ea4b23509 100644 --- a/providers/cognito/cognito.go +++ b/providers/cognito/cognito.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -128,7 +127,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/dailymotion/dailymotion.go b/providers/dailymotion/dailymotion.go index d3c1e1d24..a8657a596 100644 --- a/providers/dailymotion/dailymotion.go +++ b/providers/dailymotion/dailymotion.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" @@ -97,7 +96,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/deezer/deezer.go b/providers/deezer/deezer.go index a0f9b9d1d..7f5ed1f6d 100644 --- a/providers/deezer/deezer.go +++ b/providers/deezer/deezer.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -98,7 +97,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/digitalocean/digitalocean.go b/providers/digitalocean/digitalocean.go index 69a7a639e..560952f7f 100644 --- a/providers/digitalocean/digitalocean.go +++ b/providers/digitalocean/digitalocean.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -105,7 +104,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode) } - bits, err := ioutil.ReadAll(resp.Body) + bits, err := io.ReadAll(resp.Body) if err != nil { return user, err } diff --git a/providers/discord/discord.go b/providers/discord/discord.go index 9b3030f2d..75afd09f4 100644 --- a/providers/discord/discord.go +++ b/providers/discord/discord.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -143,7 +142,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode) } - bits, err := ioutil.ReadAll(resp.Body) + bits, err := io.ReadAll(resp.Body) if err != nil { return user, err } diff --git a/providers/dropbox/dropbox.go b/providers/dropbox/dropbox.go index da55dba15..e02dce853 100644 --- a/providers/dropbox/dropbox.go +++ b/providers/dropbox/dropbox.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strings" @@ -105,7 +104,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode) } - bits, err := ioutil.ReadAll(resp.Body) + bits, err := io.ReadAll(resp.Body) if err != nil { return user, err } diff --git a/providers/eveonline/eveonline.go b/providers/eveonline/eveonline.go index ad18776b6..6bf156321 100644 --- a/providers/eveonline/eveonline.go +++ b/providers/eveonline/eveonline.go @@ -6,7 +6,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/markbates/goth" @@ -102,7 +102,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/facebook/facebook.go b/providers/facebook/facebook.go index 23773ca34..f740f46f5 100644 --- a/providers/facebook/facebook.go +++ b/providers/facebook/facebook.go @@ -11,7 +11,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -127,7 +126,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/gitea/gitea.go b/providers/gitea/gitea.go index 6156df176..d04f2046c 100644 --- a/providers/gitea/gitea.go +++ b/providers/gitea/gitea.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -115,7 +114,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/github/github.go b/providers/github/github.go index 962d07a33..37efff9de 100644 --- a/providers/github/github.go +++ b/providers/github/github.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strconv" "strings" @@ -126,7 +125,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("GitHub API responded with a %d trying to fetch user information", response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/gitlab/gitlab.go b/providers/gitlab/gitlab.go index e5457cf0a..e3561eb8b 100644 --- a/providers/gitlab/gitlab.go +++ b/providers/gitlab/gitlab.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -116,7 +115,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/google/google.go b/providers/google/google.go index a266c91a2..629afb418 100644 --- a/providers/google/google.go +++ b/providers/google/google.go @@ -5,7 +5,7 @@ package google import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -110,7 +110,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - responseBytes, err := ioutil.ReadAll(response.Body) + responseBytes, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/gplus/gplus.go b/providers/gplus/gplus.go index 61e9a0ea0..832d723ad 100644 --- a/providers/gplus/gplus.go +++ b/providers/gplus/gplus.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -102,7 +101,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/hubspot/hubspot.go b/providers/hubspot/hubspot.go index 10b292ddc..36b5dd843 100644 --- a/providers/hubspot/hubspot.go +++ b/providers/hubspot/hubspot.go @@ -3,13 +3,14 @@ package hubspot import ( "encoding/json" "fmt" - "github.com/markbates/goth" - "golang.org/x/oauth2" "io" "net/http" "net/url" "strconv" "time" + + "github.com/markbates/goth" + "golang.org/x/oauth2" ) // These vars define the Authentication and Token URLS for Hubspot. diff --git a/providers/influxcloud/influxcloud.go b/providers/influxcloud/influxcloud.go index 7f7ad94c6..220cb103c 100644 --- a/providers/influxcloud/influxcloud.go +++ b/providers/influxcloud/influxcloud.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -129,7 +128,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/instagram/instagram.go b/providers/instagram/instagram.go index b4703dc44..0d1c9cc79 100644 --- a/providers/instagram/instagram.go +++ b/providers/instagram/instagram.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" @@ -97,7 +96,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/intercom/intercom.go b/providers/intercom/intercom.go index b58e864ae..4d2e27834 100644 --- a/providers/intercom/intercom.go +++ b/providers/intercom/intercom.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strings" @@ -105,7 +104,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/kakao/kakao.go b/providers/kakao/kakao.go index f19e35ad8..15d97c43f 100644 --- a/providers/kakao/kakao.go +++ b/providers/kakao/kakao.go @@ -6,7 +6,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strconv" @@ -105,7 +105,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/lastfm/lastfm.go b/providers/lastfm/lastfm.go index ad30e8d07..3d844455a 100644 --- a/providers/lastfm/lastfm.go +++ b/providers/lastfm/lastfm.go @@ -8,7 +8,7 @@ import ( "encoding/xml" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "sort" @@ -168,7 +168,7 @@ func (p *Provider) request(sign bool, params map[string]string, result interface err = errors.New(fmt.Errorf("Request error(%v) %v", res.StatusCode, res.Status).Error()) return err } - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return err } diff --git a/providers/line/line.go b/providers/line/line.go index e4d2e9555..41cea75b4 100644 --- a/providers/line/line.go +++ b/providers/line/line.go @@ -6,7 +6,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/markbates/goth" @@ -105,7 +105,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/mailru/mailru.go b/providers/mailru/mailru.go index db38280e2..f1d15ea0d 100644 --- a/providers/mailru/mailru.go +++ b/providers/mailru/mailru.go @@ -5,7 +5,7 @@ package mailru import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/markbates/goth" @@ -101,7 +101,7 @@ func (p *Provider) FetchUser(session goth.Session) (_ goth.User, err error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.name, res.StatusCode) } - buf, err := ioutil.ReadAll(res.Body) + buf, err := io.ReadAll(res.Body) if err != nil { return user, err } diff --git a/providers/mastodon/mastodon.go b/providers/mastodon/mastodon.go index a69788d20..58c018cec 100644 --- a/providers/mastodon/mastodon.go +++ b/providers/mastodon/mastodon.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "strings" @@ -112,7 +111,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/meetup/meetup.go b/providers/meetup/meetup.go index 3d1ef0c8c..94aa053b5 100644 --- a/providers/meetup/meetup.go +++ b/providers/meetup/meetup.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "strconv" @@ -104,7 +103,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/naver/naver.go b/providers/naver/naver.go index dad6beb89..2ebce639a 100644 --- a/providers/naver/naver.go +++ b/providers/naver/naver.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -72,7 +71,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/nextcloud/README.md b/providers/nextcloud/README.md index 841668fdc..ae7d5668d 100644 --- a/providers/nextcloud/README.md +++ b/providers/nextcloud/README.md @@ -6,7 +6,7 @@ on your own private server. ## Setting up Nextcloud Test Environment To test, you only need a working Docker image of Nextcloud running on a public -URL, e.g. through [traefik](https://traefik.io/) +URL, e.g. through [traefik](https://traefik.io) ```docker-compose.yml version: '2' diff --git a/providers/nextcloud/nextcloud.go b/providers/nextcloud/nextcloud.go index 23d3ee896..43bc85976 100644 --- a/providers/nextcloud/nextcloud.go +++ b/providers/nextcloud/nextcloud.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -132,7 +131,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/okta/okta.go b/providers/okta/okta.go index b53eae2b4..b871b3d38 100644 --- a/providers/okta/okta.go +++ b/providers/okta/okta.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -109,7 +108,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/onedrive/onedrive.go b/providers/onedrive/onedrive.go index dcb96e9cb..877894f83 100644 --- a/providers/onedrive/onedrive.go +++ b/providers/onedrive/onedrive.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" @@ -94,7 +93,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/openidConnect/openidConnect.go b/providers/openidConnect/openidConnect.go index 4a7215948..e33e3eda7 100644 --- a/providers/openidConnect/openidConnect.go +++ b/providers/openidConnect/openidConnect.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -288,7 +288,7 @@ func (p *Provider) RefreshTokenWithIDToken(refreshToken string) (*RefreshTokenRe return nil, fmt.Errorf("Non-200 response from RefreshToken: %d, WWW-Authenticate=%s", resp.StatusCode, resp.Header.Get("WWW-Authenticate")) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -401,7 +401,7 @@ func (p *Provider) fetchUserInfo(url, accessToken string) (map[string]interface{ // The UserInfo Claims MUST be returned as the members of a JSON object // http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -420,7 +420,7 @@ func getOpenIDConfig(p *Provider, openIDAutoDiscoveryURL string) (*OpenIDConfig, return nil, fmt.Errorf("Non-success code for Discovery URL: %d", res.StatusCode) } - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return nil, err } diff --git a/providers/patreon/patreon.go b/providers/patreon/patreon.go index a599b75e1..b960aa242 100644 --- a/providers/patreon/patreon.go +++ b/providers/patreon/patreon.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "time" @@ -143,7 +142,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/paypal/paypal.go b/providers/paypal/paypal.go index bca0b8b77..64579f6dc 100644 --- a/providers/paypal/paypal.go +++ b/providers/paypal/paypal.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -126,7 +125,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/reddit/reddit.go b/providers/reddit/reddit.go index 2843c2f57..f3d328599 100644 --- a/providers/reddit/reddit.go +++ b/providers/reddit/reddit.go @@ -3,11 +3,12 @@ package reddit import ( "encoding/json" "fmt" - "github.com/markbates/goth" - "golang.org/x/oauth2" "io" "net/http" "time" + + "github.com/markbates/goth" + "golang.org/x/oauth2" ) const ( diff --git a/providers/seatalk/seatalk.go b/providers/seatalk/seatalk.go index fd6161be6..e399eb495 100644 --- a/providers/seatalk/seatalk.go +++ b/providers/seatalk/seatalk.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -101,7 +101,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - responseBytes, err := ioutil.ReadAll(response.Body) + responseBytes, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/slack/slack.go b/providers/slack/slack.go index 84036ea96..daec6f422 100644 --- a/providers/slack/slack.go +++ b/providers/slack/slack.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -104,7 +103,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } @@ -130,7 +129,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err = ioutil.ReadAll(response.Body) + bits, err = io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/soundcloud/soundcloud.go b/providers/soundcloud/soundcloud.go index 2e11ee624..5e6dff719 100644 --- a/providers/soundcloud/soundcloud.go +++ b/providers/soundcloud/soundcloud.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -99,7 +98,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/steam/session.go b/providers/steam/session.go index 8f60dc296..7f06c8c98 100644 --- a/providers/steam/session.go +++ b/providers/steam/session.go @@ -4,7 +4,7 @@ package steam import ( "encoding/json" "errors" - "io/ioutil" + "io" "net/url" "regexp" "strings" @@ -56,7 +56,7 @@ func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, return "", err } defer resp.Body.Close() - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/providers/strava/strava.go b/providers/strava/strava.go index 785cc7fb2..4527844fe 100644 --- a/providers/strava/strava.go +++ b/providers/strava/strava.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -101,7 +100,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/tiktok/session.go b/providers/tiktok/session.go index 2430b1749..ff917c820 100644 --- a/providers/tiktok/session.go +++ b/providers/tiktok/session.go @@ -3,7 +3,7 @@ package tiktok import ( "encoding/json" "errors" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -68,7 +68,7 @@ func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, }{} // Get the body bytes in case we have to parse an error response - bodyBytes, err := ioutil.ReadAll(response.Body) + bodyBytes, err := io.ReadAll(response.Body) if err != nil { return "", err } diff --git a/providers/tiktok/tiktok.go b/providers/tiktok/tiktok.go index 1d3332188..01066b789 100644 --- a/providers/tiktok/tiktok.go +++ b/providers/tiktok/tiktok.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -143,7 +142,7 @@ func userFromReader(reader io.Reader, user *goth.User) error { } `json:"data"` }{} - bodyBytes, err := ioutil.ReadAll(reader) + bodyBytes, err := io.ReadAll(reader) if err != nil { return err } @@ -207,7 +206,7 @@ func (p *Provider) RefreshToken(refreshToken string) (*oauth2.Token, error) { } // We get the body bytes in case we need to parse an error response - bodyBytes, err := ioutil.ReadAll(refreshResponse.Body) + bodyBytes, err := io.ReadAll(refreshResponse.Body) if err != nil { return nil, err } diff --git a/providers/twitter/twitter.go b/providers/twitter/twitter.go index 4e2e2c98a..ad4abced2 100644 --- a/providers/twitter/twitter.go +++ b/providers/twitter/twitter.go @@ -7,7 +7,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "github.com/markbates/goth" @@ -118,7 +118,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/twitterv2/twitterv2.go b/providers/twitterv2/twitterv2.go index 1dcb21292..ee04ca72a 100644 --- a/providers/twitterv2/twitterv2.go +++ b/providers/twitterv2/twitterv2.go @@ -7,7 +7,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "github.com/markbates/goth" @@ -118,7 +118,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/typetalk/typetalk.go b/providers/typetalk/typetalk.go index 73aa755cd..9822cb475 100644 --- a/providers/typetalk/typetalk.go +++ b/providers/typetalk/typetalk.go @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -103,7 +102,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user name", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } @@ -133,7 +132,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch profile", p.providerName, response.StatusCode) } - bits, err = ioutil.ReadAll(response.Body) + bits, err = io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/vk/vk.go b/providers/vk/vk.go index 615c81fbd..f0619f2e5 100644 --- a/providers/vk/vk.go +++ b/providers/vk/vk.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strconv" @@ -98,7 +97,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/xero/xero.go b/providers/xero/xero.go index bb642c353..621bd6bc8 100644 --- a/providers/xero/xero.go +++ b/providers/xero/xero.go @@ -7,7 +7,7 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -155,7 +155,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { } var apiResponse APIResponse - responseBytes, err := ioutil.ReadAll(response.Body) + responseBytes, err := io.ReadAll(response.Body) if err != nil { return user, fmt.Errorf("Could not read response: %s", err.Error()) } @@ -204,7 +204,7 @@ func newPublicConsumer(provider *Provider, authURL string) *oauth.Consumer { // newPartnerConsumer creates a consumer capable of communicating with a Partner application: https://developer.xero.com/documentation/auth-and-limits/partner-applications func newPrivateOrPartnerConsumer(provider *Provider, authURL string) *oauth.Consumer { - privateKeyFileContents, err := ioutil.ReadFile(privateKeyFilePath) + privateKeyFileContents, err := os.ReadFile(privateKeyFilePath) if err != nil { log.Fatal(err) } diff --git a/providers/yammer/session.go b/providers/yammer/session.go index cd8fe781a..b39019ef9 100644 --- a/providers/yammer/session.go +++ b/providers/yammer/session.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -76,7 +75,7 @@ func retrieveAuthData(p *Provider, TokenURL string, v url.Values) (map[string]ma return nil, err } defer r.Body.Close() - body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1<<20)) + body, err := io.ReadAll(io.LimitReader(r.Body, 1<<20)) if err != nil { return nil, fmt.Errorf("oauth2: cannot fetch token: %v", err) } diff --git a/providers/yammer/yammer.go b/providers/yammer/yammer.go index f7e803ea2..bcc7a2168 100644 --- a/providers/yammer/yammer.go +++ b/providers/yammer/yammer.go @@ -7,7 +7,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "strconv" @@ -99,7 +99,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } - bits, err := ioutil.ReadAll(response.Body) + bits, err := io.ReadAll(response.Body) if err != nil { return user, err } diff --git a/providers/yandex/yandex.go b/providers/yandex/yandex.go index e550a80f3..a500564ea 100644 --- a/providers/yandex/yandex.go +++ b/providers/yandex/yandex.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "github.com/markbates/goth" @@ -103,7 +102,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode) } - bits, err := ioutil.ReadAll(resp.Body) + bits, err := io.ReadAll(resp.Body) if err != nil { return user, err }