Exemplo n.º 1
// DefaultClient returns an HTTP Client that uses the
// DefaultTokenSource to obtain authentication credentials.
// This client should be used when developing services
// that run on Google App Engine or Google Compute Engine
// and use "Application Default Credentials."
// For more details, see:
// https://developers.google.com/accounts/docs/application-default-credentials
func DefaultClient(ctx context.Context, scope ...string) (*http.Client, error) {
	ts, err := DefaultTokenSource(ctx, scope...)
	if err != nil {
		return nil, err
	return oauth2.NewClient(ctx, ts), nil
Exemplo n.º 2
// Client returns an HTTP client using the provided token.
// The token will auto-refresh as necessary. The underlying
// HTTP transport will be obtained using the provided context.
// The returned client and its Transport should not be modified.
func (c *Config) Client(ctx context.Context) *http.Client {
	return oauth2.NewClient(ctx, c.TokenSource(ctx))