"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
rc: include OAuth authorization URL in rc config/oauthstatus response
Hakan İSMAİLf2832217aa1f
diff --git a/lib/oauthutil/oauthutil.go b/lib/oauthutil/oauthutil.goindex 0e152ab69..856c881eb 100644--- a/lib/oauthutil/oauthutil.go+++ b/lib/oauthutil/oauthutil.go@@ -34,8 +34,10 @@ var (// oauthCancelFn stores the cancel function for the currently active OAuth flowoauthCancelFn context.CancelFunc- // oauthCancelMu protects oauthCancelFn+ // oauthCancelMu protects oauthCancelFn and oauthURLoauthCancelMu sync.Mutex+ // oauthURL stores the URL for the currently active OAuth flow+ oauthURL string)const (@@ -798,6 +800,7 @@ func rcOAuthStop(ctx context.Context, in rc.Params) (out rc.Params, err error) {}oauthCancelFn()oauthCancelFn = nil+ oauthURL = ""return nil, nil}@@ -810,11 +813,13 @@ func init() {Returns a JSON object:- status - "running" or "stopped"+- authUrl - URL for the authorization (only if status is "running")Eg{- "status": "running"+ "status": "running",+ "authUrl": "http://127.0.0.1:53682/auth?state=..."}`,})@@ -824,10 +829,13 @@ func rcOAuthStatus(ctx context.Context, in rc.Params) (out rc.Params, err error)oauthCancelMu.Lock()defer oauthCancelMu.Unlock()status := "stopped"+ params := rc.Params{"status": status}if oauthCancelFn != nil {status = "running"+ params["status"] = status+ params["authUrl"] = oauthURL}- return rc.Params{"status": status}, nil+ return params, nil}// Return true if can run without a webserver and just entering a code@@ -914,20 +922,23 @@ func configSetup(ctx context.Context, id, name string, m configmap.Mapper, oauthif err != nil {return "", fmt.Errorf("failed to start auth webserver: %w", err)}+ authURL = "http://" + bindAddress + "/auth?state=" + state+oauthCtx, cancel := context.WithCancel(ctx)oauthCancelMu.Lock()oauthCancelFn = cancel+ oauthURL = authURLoauthCancelMu.Unlock()go server.Serve()defer func() {oauthCancelMu.Lock()oauthCancelFn = nil+ oauthURL = ""oauthCancelMu.Unlock()cancel()server.Stop()}()- authURL = "http://" + bindAddress + "/auth?state=" + stateif !authorizeNoAutoBrowser {// Open the URL for the user to visitdiff --git a/lib/oauthutil/rc_test.go b/lib/oauthutil/rc_test.goindex 5f1aadae9..e7101ca1c 100644--- a/lib/oauthutil/rc_test.go+++ b/lib/oauthutil/rc_test.go@@ -24,10 +24,12 @@ func TestRcOAuthStatus(t *testing.T) {defer cancel()oauthCancelMu.Lock()oauthCancelFn = cancel+ oauthURL = "http://127.0.0.1:53682/auth?state=xyz"oauthCancelMu.Unlock()defer func() {oauthCancelMu.Lock()oauthCancelFn = nil+ oauthURL = ""oauthCancelMu.Unlock()}()@@ -35,6 +37,7 @@ func TestRcOAuthStatus(t *testing.T) {out, err = call.Fn(ctx2, rc.Params{})require.NoError(t, err)assert.Equal(t, "running", out["status"])+ assert.Equal(t, "http://127.0.0.1:53682/auth?state=xyz", out["authUrl"])}func TestRcOAuthStop(t *testing.T) {