From cfaa6dc2ed0aa2247eb52561ef58ff40a2efac23 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 19 Dec 2023 14:58:50 +0100 Subject: [PATCH] Revert "[TESTS] oauth2: make it possible to use an alternate http.Client" This reverts commit 172fdd0d32ab5118b84dffc55fbd8ca3cc2be392. This code was introduced for a test case that is no longer in use. It should guard against the provider being null but that's not worth the effort for deadcode. Just remove it. Refs: https://codeberg.org/forgejo/forgejo/issues/1984 --- services/auth/source/oauth2/http.go | 10 ------- .../auth/source/oauth2/providers_custom.go | 26 +++++-------------- .../auth/source/oauth2/providers_openid.go | 1 - 3 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 services/auth/source/oauth2/http.go diff --git a/services/auth/source/oauth2/http.go b/services/auth/source/oauth2/http.go deleted file mode 100644 index 1ee52412ae..0000000000 --- a/services/auth/source/oauth2/http.go +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-FileCopyrightText: Copyright the Forgejo contributors -// SPDX-License-Identifier: MIT - -package oauth2 - -import ( - "net/http" -) - -var HTTPClient *http.Client diff --git a/services/auth/source/oauth2/providers_custom.go b/services/auth/source/oauth2/providers_custom.go index 41570b699e..65cf538ad7 100644 --- a/services/auth/source/oauth2/providers_custom.go +++ b/services/auth/source/oauth2/providers_custom.go @@ -63,9 +63,7 @@ func init() { if setting.OAuth2Client.EnableAutoRegistration { scopes = append(scopes, "user:email") } - provider := github.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, custom.TokenURL, custom.ProfileURL, custom.EmailURL, scopes...) - provider.HTTPClient = HTTPClient - return provider, nil + return github.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, custom.TokenURL, custom.ProfileURL, custom.EmailURL, scopes...), nil })) RegisterGothProvider(NewCustomProvider( @@ -75,9 +73,7 @@ func init() { ProfileURL: availableAttribute(gitlab.ProfileURL), }, func(clientID, secret, callbackURL string, custom *CustomURLMapping, scopes []string) (goth.Provider, error) { scopes = append(scopes, "read_user") - provider := gitlab.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, custom.TokenURL, custom.ProfileURL, scopes...) - provider.HTTPClient = HTTPClient - return provider, nil + return gitlab.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, custom.TokenURL, custom.ProfileURL, scopes...), nil })) RegisterGothProvider(NewCustomProvider( @@ -87,9 +83,7 @@ func init() { ProfileURL: requiredAttribute(gitea.ProfileURL), }, func(clientID, secret, callbackURL string, custom *CustomURLMapping, scopes []string) (goth.Provider, error) { - provider := gitea.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, custom.TokenURL, custom.ProfileURL, scopes...) - provider.HTTPClient = HTTPClient - return provider, nil + return gitea.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, custom.TokenURL, custom.ProfileURL, scopes...), nil })) RegisterGothProvider(NewCustomProvider( @@ -99,9 +93,7 @@ func init() { ProfileURL: requiredAttribute(nextcloud.ProfileURL), }, func(clientID, secret, callbackURL string, custom *CustomURLMapping, scopes []string) (goth.Provider, error) { - provider := nextcloud.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, custom.TokenURL, custom.ProfileURL, scopes...) - provider.HTTPClient = HTTPClient - return provider, nil + return nextcloud.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, custom.TokenURL, custom.ProfileURL, scopes...), nil })) RegisterGothProvider(NewCustomProvider( @@ -109,9 +101,7 @@ func init() { AuthURL: requiredAttribute(mastodon.InstanceURL), }, func(clientID, secret, callbackURL string, custom *CustomURLMapping, scopes []string) (goth.Provider, error) { - provider := mastodon.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, scopes...) - provider.HTTPClient = HTTPClient - return provider, nil + return mastodon.NewCustomisedURL(clientID, secret, callbackURL, custom.AuthURL, scopes...), nil })) RegisterGothProvider(NewCustomProvider( @@ -124,12 +114,10 @@ func init() { azureScopes[i] = azureadv2.ScopeType(scope) } - provider := azureadv2.New(clientID, secret, callbackURL, azureadv2.ProviderOptions{ + return azureadv2.New(clientID, secret, callbackURL, azureadv2.ProviderOptions{ Tenant: azureadv2.TenantType(custom.Tenant), Scopes: azureScopes, - }) - provider.HTTPClient = HTTPClient - return provider, nil + }), nil }, )) } diff --git a/services/auth/source/oauth2/providers_openid.go b/services/auth/source/oauth2/providers_openid.go index 2acccc5624..a4dcfcafc7 100644 --- a/services/auth/source/oauth2/providers_openid.go +++ b/services/auth/source/oauth2/providers_openid.go @@ -43,7 +43,6 @@ func (o *OpenIDProvider) CreateGothProvider(providerName, callbackURL string, so if err != nil { log.Warn("Failed to create OpenID Connect Provider with name '%s' with url '%s': %v", providerName, source.OpenIDConnectAutoDiscoveryURL, err) } - provider.HTTPClient = HTTPClient return provider, err }