Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

dropbox: fix oauth configuration

Nick Craig-Wood1e88f0702af6
diff --git a/dropbox/dropbox.go b/dropbox/dropbox.go
index 157cf28ca..e4bb10dcc 100644
--- a/dropbox/dropbox.go
+++ b/dropbox/dropbox.go
@@ -75,7 +75,7 @@ func init() {
Description: "Dropbox",
NewFs: NewFs,
Config: func(name string) {
- err := oauthutil.Config("dropbox", name, dropboxConfig)
+ err := oauthutil.ConfigNoOffline("dropbox", name, dropboxConfig)
if err != nil {
log.Fatalf("Failed to configure token: %v", err)
}
diff --git a/oauthutil/oauthutil.go b/oauthutil/oauthutil.go
index 6f8948a68..a4ab71f74 100644
--- a/oauthutil/oauthutil.go
+++ b/oauthutil/oauthutil.go
@@ -250,6 +250,16 @@ func NewClient(name string, config *oauth2.Config) (*http.Client, *TokenSource,
//
// It may run an internal webserver to receive the results
func Config(id, name string, config *oauth2.Config) error {
+ return doConfig(id, name, config, true)
+}
+
+// ConfigNoOffline does the same as Config but does not pass the
+// "access_type=offline" parameter.
+func ConfigNoOffline(id, name string, config *oauth2.Config) error {
+ return doConfig(id, name, config, false)
+}
+
+func doConfig(id, name string, config *oauth2.Config, offline bool) error {
config, changed := overrideCredentials(name, config)
automatic := fs.ConfigFileGet(name, fs.ConfigAutomatic) != ""
@@ -322,7 +332,11 @@ func Config(id, name string, config *oauth2.Config) error {
return err
}
state := fmt.Sprintf("%x", stateBytes)
- authURL := config.AuthCodeURL(state, oauth2.AccessTypeOffline)
+ var opts []oauth2.AuthCodeOption
+ if offline {
+ opts = append(opts, oauth2.AccessTypeOffline)
+ }
+ authURL := config.AuthCodeURL(state, opts...)
// Prepare webserver
server := authServer{