diff options
Diffstat (limited to 'auth/oauth.go')
| -rw-r--r-- | auth/oauth.go | 18 | 
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, | 
