コード例 #1
0
ファイル: drive.go プロジェクト: newobject/camlistore
func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (blobserver.Storage, error) {
	auth := config.RequiredObject("auth")
	oauthConf := &oauth.Config{
		ClientId:     auth.RequiredString("client_id"),
		ClientSecret: auth.RequiredString("client_secret"),
		AuthURL:      GoogleOAuth2AuthURL,
		TokenURL:     GoogleOAuth2TokenURL,
	}

	// force refreshes the access token on start, make sure
	// refresh request in parallel are being started
	transport := &oauth.Transport{
		Token: &oauth.Token{
			AccessToken:  "",
			RefreshToken: auth.RequiredString("refresh_token"),
			Expiry:       time.Now(),
		},
		Config:    oauthConf,
		Transport: http.DefaultTransport,
	}

	service, err := service.New(transport, config.RequiredString("parent_id"))
	sto := &driveStorage{
		service: service,
	}
	return sto, err
}
コード例 #2
0
ファイル: drive.go プロジェクト: rfistman/camlistore
func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (blobserver.Storage, error) {
	auth := config.RequiredObject("auth")
	oAuthClient := oauth2.NewClient(oauth2.NoContext, oauthutil.NewRefreshTokenSource(&oauth2.Config{
		Scopes:       []string{Scope},
		Endpoint:     google.Endpoint,
		ClientID:     auth.RequiredString("client_id"),
		ClientSecret: auth.RequiredString("client_secret"),
		RedirectURL:  oauthutil.TitleBarRedirectURL,
	}, auth.RequiredString("refresh_token")))
	parent := config.RequiredString("parent_id")
	if err := config.Validate(); err != nil {
		return nil, err
	}
	service, err := service.New(oAuthClient, parent)
	sto := &driveStorage{
		service: service,
	}
	return sto, err
}