aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Arora2014-05-14 02:16:00 +1000
committerSumit Arora2014-05-14 02:16:00 +1000
commit377a4931b52666040d819d3c21d5eb88da8adcfa (patch)
tree6b5d9d3ec55ae07cbb832b7829b438b2562a72d0
parent79cbfc2986f4c8152de187ae2be207829d08077f (diff)
downloadgdrive-377a4931b52666040d819d3c21d5eb88da8adcfa.tar.bz2
Add an option to not prompt the user for oauth authentication
interactively. This is a no-op for the cli, where the option defaults to true. Use Case: In automation apps/scripts where gdrive/gdrive is used as a third party module (as opposed to a cli app). It is desirable to not be prompted interactively. Instead return the error and let the calling code handle it.
-rw-r--r--auth/auth.go2
-rw-r--r--drive.go2
-rw-r--r--gdrive/gdrive.go4
3 files changed, 4 insertions, 4 deletions
diff --git a/auth/auth.go b/auth/auth.go
index ed65920..22267da 100644
--- a/auth/auth.go
+++ b/auth/auth.go
@@ -35,7 +35,7 @@ func hasValidToken(cacheFile oauth.CacheFile, transport *oauth.Transport) bool {
return true
}
-func GetOauth2Client(clientId, clientSecret, cachePath string) (*http.Client, error) {
+func GetOauth2Client(clientId, clientSecret, cachePath string, promptUser bool) (*http.Client, error) {
cacheFile := oauth.CacheFile(cachePath)
config := &oauth.Config{
diff --git a/drive.go b/drive.go
index 05d1da0..f32ad9c 100644
--- a/drive.go
+++ b/drive.go
@@ -85,7 +85,7 @@ func main() {
}
// Get authorized drive client
- drive, err := gdrive.New(opts.AppPath, opts.Advanced)
+ drive, err := gdrive.New(opts.AppPath, opts.Advanced, true)
if err != nil {
writeError("An error occurred creating Drive client: %v\n", err)
}
diff --git a/gdrive/gdrive.go b/gdrive/gdrive.go
index 883ebaf..45458b2 100644
--- a/gdrive/gdrive.go
+++ b/gdrive/gdrive.go
@@ -28,7 +28,7 @@ func (self *Drive) Client() *http.Client {
return self.client
}
-func New(customAppPath string, advancedMode bool) (*Drive, error) {
+func New(customAppPath string, advancedMode bool, promptUser bool) (*Drive, error) {
if customAppPath != "" {
AppPath = customAppPath
}
@@ -38,7 +38,7 @@ func New(customAppPath string, advancedMode bool) (*Drive, error) {
tokenPath := filepath.Join(AppPath, TokenFname)
config := config.Load(configPath, advancedMode)
- client, err := auth.GetOauth2Client(config.ClientId, config.ClientSecret, tokenPath)
+ client, err := auth.GetOauth2Client(config.ClientId, config.ClientSecret, tokenPath, promptUser)
if err != nil {
return nil, err
}