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

rc/rcserver: with --rc-files if auth set, pass on to URL opened

Nick Craig-Wood75a88de55c8b
diff --git a/docs/content/rc.md b/docs/content/rc.md
index c2a4ca7e5..9aeaaea27 100644
--- a/docs/content/rc.md
+++ b/docs/content/rc.md
@@ -79,6 +79,10 @@ If this is set then rclone will serve the files in that directory. It
will also open the root in the web browser if specified. This is for
implementing browser based GUIs for rclone functions.
+If `--rc-user` or `--rc-pass` is set then the URL that is opened will
+have the authorization in the URL in the `http://user:pass@localhost/`
+style.
+
Default Off.
### --rc-no-auth
diff --git a/fs/rc/rcserver/rcserver.go b/fs/rc/rcserver/rcserver.go
index e8d187031..b52718e2f 100644
--- a/fs/rc/rcserver/rcserver.go
+++ b/fs/rc/rcserver/rcserver.go
@@ -69,7 +69,16 @@ func (s *Server) Serve() error {
fs.Logf(nil, "Serving remote control on %s", s.URL())
// Open the files in the browser if set
if s.files != nil {
- _ = open.Start(s.URL())
+ openURL, err := url.Parse(s.URL())
+ if err != nil {
+ return errors.Wrap(err, "invalid serving URL")
+ }
+ // Add username, password into the URL if they are set
+ user, pass := s.opt.HTTPOptions.BasicUser, s.opt.HTTPOptions.BasicPass
+ if user != "" || pass != "" {
+ openURL.User = url.UserPassword(user, pass)
+ }
+ _ = open.Start(openURL.String())
}
return nil
}