From 298493f3775a6a016ad575344097724e03a2671a Mon Sep 17 00:00:00 2001 From: Derek Duncan Date: Wed, 24 Jul 2024 23:40:06 -0500 Subject: [PATCH 1/8] update to go 1.22, add support for mux route param, remove ioutil references --- .gitignore | 1 + go.mod | 2 +- go.sum | 1 + gothic/gothic.go | 9 ++++++--- gothic/gothic_test.go | 8 +++++--- providers/amazon/amazon.go | 3 +-- providers/azureadv2/azureadv2.go | 3 +-- providers/battlenet/battlenet.go | 4 ++-- providers/bitbucket/bitbucket.go | 4 ++-- providers/bitly/bitly.go | 3 +-- providers/classlink/provider.go | 4 ++-- providers/cloudfoundry/cf.go | 3 +-- providers/cognito/cognito.go | 3 +-- providers/dailymotion/dailymotion.go | 3 +-- providers/deezer/deezer.go | 3 +-- providers/digitalocean/digitalocean.go | 3 +-- providers/discord/discord.go | 3 +-- providers/dropbox/dropbox.go | 3 +-- providers/eveonline/eveonline.go | 4 ++-- providers/facebook/facebook.go | 3 +-- providers/gitea/gitea.go | 3 +-- providers/github/github.go | 3 +-- providers/gitlab/gitlab.go | 3 +-- providers/google/google.go | 4 ++-- providers/gplus/gplus.go | 3 +-- providers/hubspot/hubspot.go | 5 +++-- providers/influxcloud/influxcloud.go | 3 +-- providers/instagram/instagram.go | 3 +-- providers/intercom/intercom.go | 9 ++++----- providers/intercom/intercom_test.go | 6 +++--- providers/kakao/kakao.go | 4 ++-- providers/lastfm/lastfm.go | 4 ++-- providers/line/line.go | 4 ++-- providers/mailru/mailru.go | 4 ++-- providers/mastodon/mastodon.go | 3 +-- providers/meetup/meetup.go | 3 +-- providers/naver/naver.go | 3 +-- providers/nextcloud/README.md | 2 +- providers/nextcloud/nextcloud.go | 3 +-- providers/okta/okta.go | 3 +-- providers/onedrive/onedrive.go | 3 +-- providers/openidConnect/openidConnect.go | 8 ++++---- providers/patreon/patreon.go | 3 +-- providers/paypal/paypal.go | 3 +-- providers/reddit/reddit.go | 5 +++-- providers/seatalk/seatalk.go | 4 ++-- providers/slack/slack.go | 5 ++--- providers/soundcloud/soundcloud.go | 3 +-- providers/steam/session.go | 4 ++-- providers/strava/strava.go | 3 +-- providers/tiktok/session.go | 4 ++-- providers/tiktok/tiktok.go | 5 ++--- providers/twitter/twitter.go | 4 ++-- providers/twitterv2/twitterv2.go | 4 ++-- providers/typetalk/typetalk.go | 5 ++--- providers/vk/vk.go | 3 +-- providers/xero/xero.go | 6 +++--- providers/yammer/session.go | 3 +-- providers/yammer/yammer.go | 4 ++-- providers/yandex/yandex.go | 3 +-- providers/zoom/zoom_test.go | 4 ++-- 61 files changed, 103 insertions(+), 128 deletions(-) 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.mod b/go.mod index bff421fcd..0398f9ebc 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/markbates/goth -go 1.18 +go 1.22 require ( github.com/go-chi/chi/v5 v5.1.0 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..17b89c71a 100644 --- a/gothic/gothic.go +++ b/gothic/gothic.go @@ -16,7 +16,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -262,7 +261,6 @@ func Logout(res http.ResponseWriter, req *http.Request) error { 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 @@ -288,6 +286,11 @@ func getProviderName(req *http.Request) (string, error) { 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 @@ -347,7 +350,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..e11666e11 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" @@ -98,8 +98,9 @@ func Test_GetAuthURL(t *testing.T) { a := assert.New(t) res := httptest.NewRecorder() - req, err := http.NewRequest("GET", "/auth?provider=faux", nil) + req, err := http.NewRequest("GET", "/auth", nil) a.NoError(err) + req.SetPathValue("provider", "faux") u, err := GetAuthURL(res, req) a.NoError(err) @@ -118,6 +119,7 @@ func Test_GetAuthURL(t *testing.T) { // 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 := GetAuthURL(httptest.NewRecorder(), req2) a.NoError(err) parsed2, err := url.Parse(url2) @@ -283,7 +285,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/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..c34039b78 100644 --- a/providers/intercom/intercom.go +++ b/providers/intercom/intercom.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strings" @@ -16,9 +15,9 @@ import ( ) var ( - authURL = "https://app.intercom.io/oauth" - tokenURL = "https://api.intercom.io/auth/eagle/token?client_secret=%s" - UserURL = "https://api.intercom.io/me" + authURL = "https://app.intercom.iooauth" + tokenURL = "https://api.intercom.ioauth/eagle/token?client_secret=%s" + UserURL = "https://api.intercom.iome" ) // New creates the new Intercom provider @@ -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/intercom/intercom_test.go b/providers/intercom/intercom_test.go index 2fa3e98e7..bc67f622d 100644 --- a/providers/intercom/intercom_test.go +++ b/providers/intercom/intercom_test.go @@ -47,7 +47,7 @@ func Test_BeginAuth(t *testing.T) { session, err := provider.BeginAuth("test_state") s := session.(*intercom.Session) a.NoError(err) - a.Contains(s.AuthURL, "https://app.intercom.io/oauth") + a.Contains(s.AuthURL, "https://app.intercom.iooauth") a.Contains(s.AuthURL, fmt.Sprintf("client_id=%s", os.Getenv("INTERCOM_KEY"))) a.Contains(s.AuthURL, "state=test_state") } @@ -58,10 +58,10 @@ func Test_SessionFromJSON(t *testing.T) { provider := intercomProvider() - s, err := provider.UnmarshalSession(`{"AuthURL":"https://app.intercom.io/oauth","AccessToken":"1234567890"}`) + s, err := provider.UnmarshalSession(`{"AuthURL":"https://app.intercom.iooauth","AccessToken":"1234567890"}`) a.NoError(err) session := s.(*intercom.Session) - a.Equal(session.AuthURL, "https://app.intercom.io/oauth") + a.Equal(session.AuthURL, "https://app.intercom.iooauth") a.Equal(session.AccessToken, "1234567890") } 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 } diff --git a/providers/zoom/zoom_test.go b/providers/zoom/zoom_test.go index b90263dfe..48f6a4ca3 100644 --- a/providers/zoom/zoom_test.go +++ b/providers/zoom/zoom_test.go @@ -47,9 +47,9 @@ func Test_SessionFromJSON(t *testing.T) { provider := zoomProvider() - s, err := provider.UnmarshalSession(`{"AuthURL":"https://app.zoom.io/oauth","AccessToken":"1234567890"}`) + s, err := provider.UnmarshalSession(`{"AuthURL":"https://app.zoom.iooauth","AccessToken":"1234567890"}`) a.NoError(err) session := s.(*zoom.Session) - a.Equal(session.AuthURL, "https://app.zoom.io/oauth") + a.Equal(session.AuthURL, "https://app.zoom.iooauth") a.Equal(session.AccessToken, "1234567890") } From b3e5a4c0de15ed1a845a833260403b6d3c8d1767 Mon Sep 17 00:00:00 2001 From: Derek Duncan Date: Fri, 26 Jul 2024 06:57:21 -0500 Subject: [PATCH 2/8] revert changed AuthURL --- providers/intercom/intercom.go | 6 +++--- providers/intercom/intercom_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/providers/intercom/intercom.go b/providers/intercom/intercom.go index c34039b78..4d2e27834 100644 --- a/providers/intercom/intercom.go +++ b/providers/intercom/intercom.go @@ -15,9 +15,9 @@ import ( ) var ( - authURL = "https://app.intercom.iooauth" - tokenURL = "https://api.intercom.ioauth/eagle/token?client_secret=%s" - UserURL = "https://api.intercom.iome" + authURL = "https://app.intercom.io/oauth" + tokenURL = "https://api.intercom.io/auth/eagle/token?client_secret=%s" + UserURL = "https://api.intercom.io/me" ) // New creates the new Intercom provider diff --git a/providers/intercom/intercom_test.go b/providers/intercom/intercom_test.go index bc67f622d..2fa3e98e7 100644 --- a/providers/intercom/intercom_test.go +++ b/providers/intercom/intercom_test.go @@ -47,7 +47,7 @@ func Test_BeginAuth(t *testing.T) { session, err := provider.BeginAuth("test_state") s := session.(*intercom.Session) a.NoError(err) - a.Contains(s.AuthURL, "https://app.intercom.iooauth") + a.Contains(s.AuthURL, "https://app.intercom.io/oauth") a.Contains(s.AuthURL, fmt.Sprintf("client_id=%s", os.Getenv("INTERCOM_KEY"))) a.Contains(s.AuthURL, "state=test_state") } @@ -58,10 +58,10 @@ func Test_SessionFromJSON(t *testing.T) { provider := intercomProvider() - s, err := provider.UnmarshalSession(`{"AuthURL":"https://app.intercom.iooauth","AccessToken":"1234567890"}`) + s, err := provider.UnmarshalSession(`{"AuthURL":"https://app.intercom.io/oauth","AccessToken":"1234567890"}`) a.NoError(err) session := s.(*intercom.Session) - a.Equal(session.AuthURL, "https://app.intercom.iooauth") + a.Equal(session.AuthURL, "https://app.intercom.io/oauth") a.Equal(session.AccessToken, "1234567890") } From dc67b25054442c9123e2360ed1739d3c7c16c551 Mon Sep 17 00:00:00 2001 From: Derek Duncan Date: Fri, 26 Jul 2024 07:11:04 -0500 Subject: [PATCH 3/8] add back zoom example url --- providers/zoom/zoom_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/zoom/zoom_test.go b/providers/zoom/zoom_test.go index 48f6a4ca3..b90263dfe 100644 --- a/providers/zoom/zoom_test.go +++ b/providers/zoom/zoom_test.go @@ -47,9 +47,9 @@ func Test_SessionFromJSON(t *testing.T) { provider := zoomProvider() - s, err := provider.UnmarshalSession(`{"AuthURL":"https://app.zoom.iooauth","AccessToken":"1234567890"}`) + s, err := provider.UnmarshalSession(`{"AuthURL":"https://app.zoom.io/oauth","AccessToken":"1234567890"}`) a.NoError(err) session := s.(*zoom.Session) - a.Equal(session.AuthURL, "https://app.zoom.iooauth") + a.Equal(session.AuthURL, "https://app.zoom.io/oauth") a.Equal(session.AccessToken, "1234567890") } From 8e29d821acf2bc7c7699bc5a54dac00907f69daa Mon Sep 17 00:00:00 2001 From: Derek Duncan Date: Fri, 26 Jul 2024 07:29:59 -0500 Subject: [PATCH 4/8] update CI to only build for 1.22 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e64c2120..83a6e9457 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: test: strategy: matrix: - go-version: [ 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x ] + go-version: [ 1.22.x ] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: From 30e5b16ddb27687e52f1c8393534675ffa3907d6 Mon Sep 17 00:00:00 2001 From: Derek Duncan Date: Sat, 3 Aug 2024 06:25:17 +0000 Subject: [PATCH 5/8] testing version tags --- gothic/gothic.go | 60 --------------------------------- gothic/provider.go | 71 +++++++++++++++++++++++++++++++++++++++ gothic/provider_legacy.go | 66 ++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 60 deletions(-) create mode 100644 gothic/provider.go create mode 100644 gothic/provider_legacy.go diff --git a/gothic/gothic.go b/gothic/gothic.go index 17b89c71a..b895a12d1 100644 --- a/gothic/gothic.go +++ b/gothic/gothic.go @@ -21,8 +21,6 @@ import ( "os" "strings" - "github.com/go-chi/chi/v5" - "github.com/gorilla/mux" "github.com/gorilla/sessions" "github.com/markbates/goth" ) @@ -253,64 +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 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") -} - // 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)) 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") +} From 7203aba15b0a6bddac997c64a9da11d5cab46b54 Mon Sep 17 00:00:00 2001 From: Derek Duncan Date: Sat, 3 Aug 2024 01:40:07 -0500 Subject: [PATCH 6/8] lower go version --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0398f9ebc..bff421fcd 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/markbates/goth -go 1.22 +go 1.18 require ( github.com/go-chi/chi/v5 v5.1.0 From 96a9aba3391f0d0dd5039e18f54d52be654ad958 Mon Sep 17 00:00:00 2001 From: Derek Duncan Date: Sat, 3 Aug 2024 01:43:15 -0500 Subject: [PATCH 7/8] revert ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83a6e9457..8e64c2120 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: test: strategy: matrix: - go-version: [ 1.22.x ] + go-version: [ 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x ] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: From 356ad6ba5c92ee213e0c3b4346edb4688e4249ca Mon Sep 17 00:00:00 2001 From: Derek Duncan Date: Sat, 3 Aug 2024 10:21:08 -0500 Subject: [PATCH 8/8] move 1.22 mux tests outside of primary test file --- gothic/gothic_test.go | 4 +--- gothic/provider_test.go | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 gothic/provider_test.go diff --git a/gothic/gothic_test.go b/gothic/gothic_test.go index e11666e11..22c8448a2 100644 --- a/gothic/gothic_test.go +++ b/gothic/gothic_test.go @@ -98,9 +98,8 @@ func Test_GetAuthURL(t *testing.T) { a := assert.New(t) res := httptest.NewRecorder() - req, err := http.NewRequest("GET", "/auth", nil) + req, err := http.NewRequest("GET", "/auth?provider=faux", nil) a.NoError(err) - req.SetPathValue("provider", "faux") u, err := GetAuthURL(res, req) a.NoError(err) @@ -119,7 +118,6 @@ func Test_GetAuthURL(t *testing.T) { // 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 := GetAuthURL(httptest.NewRecorder(), req2) a.NoError(err) parsed2, err := url.Parse(url2) 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")) +}