aboutsummaryrefslogtreecommitdiffstats
path: root/auth/oauth.go
diff options
context:
space:
mode:
authorPetter Rasmussen2017-02-01 23:59:09 +0100
committerGitHub2017-02-01 23:59:09 +0100
commit9a97a02661da67824828193fd90d6eb4bda67811 (patch)
treeaec26d4e9e10bb0abcb405c84facf8217af68fc7 /auth/oauth.go
parent0e05cfb6f84a714f9bdafade6d3cddbb8c8273e9 (diff)
parentb33b3e96eb6443ae3dff61e0e7b38bb529e328ea (diff)
downloadgdrive-9a97a02661da67824828193fd90d6eb4bda67811.tar.bz2
Merge pull request #252 from fab-io/master
New feature, support authentication via service account.
Diffstat (limited to 'auth/oauth.go')
-rw-r--r--auth/oauth.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/auth/oauth.go b/auth/oauth.go
index 150642c..bc56738 100644
--- a/auth/oauth.go
+++ b/auth/oauth.go
@@ -3,6 +3,7 @@ package auth
import (
"fmt"
"golang.org/x/oauth2"
+ "golang.org/x/oauth2/google"
"net/http"
"time"
)
@@ -64,6 +65,23 @@ func NewAccessTokenClient(clientId, clientSecret, accessToken string) *http.Clie
)
}
+func NewServiceAccountClient(serviceAccountFile string) (*http.Client, error) {
+ content, exists, err := ReadFile(serviceAccountFile)
+ if(!exists) {
+ return nil, fmt.Errorf("Service account filename %q not found", serviceAccountFile)
+ }
+
+ if(err != nil) {
+ return nil, err
+ }
+
+ conf, err := google.JWTConfigFromJSON(content, "https://www.googleapis.com/auth/drive")
+ if(err != nil) {
+ return nil, err
+ }
+ return conf.Client(oauth2.NoContext), nil
+}
+
func getConfig(clientId, clientSecret string) *oauth2.Config {
return &oauth2.Config{
ClientID: clientId,