forked from TrueCloudLab/rclone
config: do not open browser on headless if google fs
On google fs (drive, google photos, and google cloud storage), if headless is selected, do not open browser. This also supplies a new option "auth-no-open-browser" for authorize if the user does not want it. This should fix #3323.
This commit is contained in:
parent
1ce1ea34aa
commit
520ddbcceb
4 changed files with 32 additions and 7 deletions
|
@ -3,11 +3,18 @@ package authorize
|
||||||
import (
|
import (
|
||||||
"github.com/rclone/rclone/cmd"
|
"github.com/rclone/rclone/cmd"
|
||||||
"github.com/rclone/rclone/fs/config"
|
"github.com/rclone/rclone/fs/config"
|
||||||
|
"github.com/rclone/rclone/fs/config/flags"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
noAutoBrowser bool
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmd.Root.AddCommand(commandDefinition)
|
cmd.Root.AddCommand(commandDefinition)
|
||||||
|
cmdFlags := commandDefinition.Flags()
|
||||||
|
flags.BoolVarP(cmdFlags, &noAutoBrowser, "auth-no-open-browser", "", false, "Do not automatically open auth link in default browser")
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandDefinition = &cobra.Command{
|
var commandDefinition = &cobra.Command{
|
||||||
|
@ -16,9 +23,12 @@ var commandDefinition = &cobra.Command{
|
||||||
Long: `
|
Long: `
|
||||||
Remote authorization. Used to authorize a remote or headless
|
Remote authorization. Used to authorize a remote or headless
|
||||||
rclone from a machine with a browser - use as instructed by
|
rclone from a machine with a browser - use as instructed by
|
||||||
rclone config.`,
|
rclone config.
|
||||||
|
|
||||||
|
Use the --auth-no-open-browser to prevent rclone to open auth
|
||||||
|
link in default browser automatically.`,
|
||||||
Run: func(command *cobra.Command, args []string) {
|
Run: func(command *cobra.Command, args []string) {
|
||||||
cmd.CheckArgs(1, 3, command, args)
|
cmd.CheckArgs(1, 3, command, args)
|
||||||
config.Authorize(args)
|
config.Authorize(args, noAutoBrowser)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@ rclone authorize [flags]
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
-h, --help help for authorize
|
--auth-no-open-browser Do not automatically open auth link in default browser
|
||||||
|
-h, --help help for authorize
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [global flags page](/flags/) for global options not listed here.
|
See the [global flags page](/flags/) for global options not listed here.
|
||||||
|
|
|
@ -62,6 +62,9 @@ const (
|
||||||
|
|
||||||
// ConfigAuthorize indicates that we just want "rclone authorize"
|
// ConfigAuthorize indicates that we just want "rclone authorize"
|
||||||
ConfigAuthorize = "config_authorize"
|
ConfigAuthorize = "config_authorize"
|
||||||
|
|
||||||
|
// ConfigAuthNoBrowser indicates that we do not want to open browser
|
||||||
|
ConfigAuthNoBrowser = "config_auth_no_browser"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Global
|
// Global
|
||||||
|
@ -1299,7 +1302,7 @@ func SetPassword() {
|
||||||
//
|
//
|
||||||
// rclone authorize "fs name"
|
// rclone authorize "fs name"
|
||||||
// rclone authorize "fs name" "client id" "client secret"
|
// rclone authorize "fs name" "client id" "client secret"
|
||||||
func Authorize(args []string) {
|
func Authorize(args []string, noAutoBrowser bool) {
|
||||||
defer suppressConfirm()()
|
defer suppressConfirm()()
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
case 1, 3:
|
case 1, 3:
|
||||||
|
@ -1319,10 +1322,15 @@ func Authorize(args []string) {
|
||||||
|
|
||||||
// Indicate that we are running rclone authorize
|
// Indicate that we are running rclone authorize
|
||||||
getConfigData().SetValue(name, ConfigAuthorize, "true")
|
getConfigData().SetValue(name, ConfigAuthorize, "true")
|
||||||
|
if noAutoBrowser {
|
||||||
|
getConfigData().SetValue(name, ConfigAuthNoBrowser, "true")
|
||||||
|
}
|
||||||
|
|
||||||
if len(args) == 3 {
|
if len(args) == 3 {
|
||||||
getConfigData().SetValue(name, ConfigClientID, args[1])
|
getConfigData().SetValue(name, ConfigClientID, args[1])
|
||||||
getConfigData().SetValue(name, ConfigClientSecret, args[2])
|
getConfigData().SetValue(name, ConfigClientSecret, args[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
m := fs.ConfigMap(f, name)
|
m := fs.ConfigMap(f, name)
|
||||||
f.Config(name, m)
|
f.Config(name, m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,6 +386,8 @@ func doConfig(id, name string, m configmap.Mapper, oauthConfig *oauth2.Config, o
|
||||||
oauthConfig, changed := overrideCredentials(name, m, oauthConfig)
|
oauthConfig, changed := overrideCredentials(name, m, oauthConfig)
|
||||||
authorizeOnlyValue, ok := m.Get(config.ConfigAuthorize)
|
authorizeOnlyValue, ok := m.Get(config.ConfigAuthorize)
|
||||||
authorizeOnly := ok && authorizeOnlyValue != "" // set if being run by "rclone authorize"
|
authorizeOnly := ok && authorizeOnlyValue != "" // set if being run by "rclone authorize"
|
||||||
|
authorizeNoAutoBrowserValue, ok := m.Get(config.ConfigAuthNoBrowser)
|
||||||
|
authorizeNoAutoBrowser := ok && authorizeNoAutoBrowserValue != ""
|
||||||
|
|
||||||
// See if already have a token
|
// See if already have a token
|
||||||
tokenString, ok := m.Get("token")
|
tokenString, ok := m.Get("token")
|
||||||
|
@ -470,9 +472,13 @@ func doConfig(id, name string, m configmap.Mapper, oauthConfig *oauth2.Config, o
|
||||||
authURL = "http://" + bindAddress + "/auth?state=" + state
|
authURL = "http://" + bindAddress + "/auth?state=" + state
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the URL for the user to visit
|
if !authorizeNoAutoBrowser && oauthConfig.RedirectURL != TitleBarRedirectURL {
|
||||||
_ = open.Start(authURL)
|
// Open the URL for the user to visit
|
||||||
fmt.Printf("If your browser doesn't open automatically go to the following link: %s\n", authURL)
|
_ = open.Start(authURL)
|
||||||
|
fmt.Printf("If your browser doesn't open automatically go to the following link: %s\n", authURL)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Please go to the following link: %s\n", authURL)
|
||||||
|
}
|
||||||
fmt.Printf("Log in and authorize rclone for access\n")
|
fmt.Printf("Log in and authorize rclone for access\n")
|
||||||
|
|
||||||
// Read the code via the webserver or manually
|
// Read the code via the webserver or manually
|
||||||
|
|
Loading…
Reference in a new issue