Functions
func AddAuthorizationMiddleware
func AddAuthorizationMiddleware(client *http.Client, tp auth.TokenProvider) error
AddAuthorizationMiddleware adds a middleware to the provided client's transport that sets the Authorization header with the value produced by the provided [cloud.google.com/go/auth.TokenProvider]. An error is returned only if client or tp is nil.
func NewClient
NewClient returns a [net/http.Client] that can be used to communicate with a Google cloud service, configured with the provided [Options]. It automatically appends Authorization headers to all outgoing requests.
func SetAuthHeader
SetAuthHeader uses the provided token to set the Authorization header on a request. If the token.Type is empty, the type is assumed to be Bearer.
ClientCertProvider
type ClientCertProvider = func(*tls.CertificateRequestInfo) (*tls.Certificate, error)
ClientCertProvider is a function that returns a TLS client certificate to be used when opening TLS connections. It follows the same semantics as [crypto/tls.Config.GetClientCertificate].
InternalOptions
type InternalOptions struct {
// EnableJWTWithScope specifies if scope can be used with self-signed JWT.
EnableJWTWithScope bool
// DefaultAudience specifies a default audience to be used as the audience
// field ("aud") for the JWT token authentication.
DefaultAudience string
// DefaultEndpoint specifies the default endpoint.
DefaultEndpoint string
// DefaultMTLSEndpoint specifies the default mTLS endpoint.
DefaultMTLSEndpoint string
// DefaultScopes specifies the default OAuth2 scopes to be used for a
// service.
DefaultScopes []string
}
InternalOptions are only meant to be set by generated client code. These are not meant to be set directly by consumers of this package. Configuration in this type is considered EXPERIMENTAL and may be removed at any time in the future without warning.
Options
type Options struct {
// DisableTelemetry disables default telemetry (OpenCensus). An example
// reason to do so would be to bind custom telemetry that overrides the
// defaults.
DisableTelemetry bool
// DisableAuthentication specifies that no authentication should be used. It
// is suitable only for testing and for accessing public resources, like
// public Google Cloud Storage buckets.
DisableAuthentication bool
// Headers are extra HTTP headers that will be appended to every outgoing
// request.
Headers http.Header
// Endpoint overrides the default endpoint to be used for a service.
Endpoint string
// APIKey specifies an API key to be used as the basis for authentication.
// If set DetectOpts are ignored.
APIKey string
// TokenProvider specifies the provider used to add Authorization header to
// all requests. If set DetectOpts are ignored.
TokenProvider auth.TokenProvider
// ClientCertProvider is a function that returns a TLS client certificate to
// be used when opening TLS connections. It follows the same semantics as
// crypto/tls.Config.GetClientCertificate.
ClientCertProvider ClientCertProvider
// DetectOpts configures settings for detect Application Default
// Credentials.
DetectOpts *detect.Options
// InternalOptions are NOT meant to be set directly by consumers of this
// package, they should only be set by generated client code.
InternalOptions *InternalOptions
}
Options used to configure a [net/http.Client] from [NewClient].