Merge ee57baae3c7b721871690857e711757f80597d6f into 205667143c807103b493e94bc0a708e10c435598

This commit is contained in:
PA733 2025-04-08 12:40:42 +01:00 committed by GitHub
commit 6e3d4629d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View File

@ -49,6 +49,9 @@ const (
// ConfigClientCredentials - use OAUTH2 client credentials
ConfigClientCredentials = "client_credentials"
// ConfigAuthServerBindAddress is the local bind address for OAuth callback server
ConfigAuthServerBindAddress = "auth_bind_addr"
// ConfigEncoding is the config key to change the encoding for a backend
ConfigEncoding = "encoding"

View File

@ -41,11 +41,8 @@ const (
// bindPort is the port that we bind the local webserver to
bindPort = "53682"
// bindAddress is binding for local webserver when active
bindAddress = "127.0.0.1:" + bindPort
// RedirectURL is redirect to local webserver when active
RedirectURL = "http://" + bindAddress + "/"
RedirectURL = "http://127.0.0.1:" + bindPort + "/"
// RedirectPublicURL is redirect to local webserver when active with public name
RedirectPublicURL = "http://localhost.rclone.org:" + bindPort + "/"
@ -157,6 +154,11 @@ var SharedOptions = []fs.Option{{
Default: false,
Help: "Use client credentials OAuth flow.\n\nThis will use the OAUTH2 client Credentials Flow as described in RFC 6749.",
Advanced: true,
}, {
Name: config.ConfigAuthServerBindAddress,
Default: "127.0.0.1",
Help: "Local bind address for OAuth callback server.\n\nLeave blank to use the default of 127.0.0.1",
Advanced: true,
}}
// oldToken contains an end-user's tokens.
@ -772,6 +774,15 @@ func noWebserverNeeded(oauthConfig *Config) bool {
return oauthConfig.RedirectURL == TitleBarRedirectURL
}
// get the bind address for the OAuth callback server
func getBindAddress(m configmap.Mapper) string {
bindAddr, ok := m.Get("auth_bind_addr")
if !ok || bindAddr == "" {
bindAddr = "127.0.0.1"
}
return bindAddr + ":" + bindPort
}
// get the URL we need to send the user to
func getAuthURL(name string, m configmap.Mapper, oauthConfig *Config, opt *Options) (authURL string, state string, err error) {
oauthConfig, _ = OverrideCredentials(name, m, oauthConfig)
@ -846,6 +857,7 @@ func configSetup(ctx context.Context, id, name string, m configmap.Mapper, oauth
}
// Prepare webserver
bindAddress := getBindAddress(m)
server := newAuthServer(opt, bindAddress, state, authURL)
err = server.Init()
if err != nil {