Package cloud.google.com/go/auth/httptransport (v0.17.0)

Note: To get more information about this package, such as access to older versions, viewthis package on pkg.go.dev.

Package httptransport provides functionality for managing HTTP clientconnections to Google Cloud services.

Functions

func AddAuthorizationMiddleware

funcAddAuthorizationMiddleware(client*http.Client,creds*auth.Credentials)error

AddAuthorizationMiddleware adds a middleware to the provided client'stransport that sets the Authorization header with the value produced by theprovided [cloud.google.com/go/auth.Credentials]. An error is returned onlyif client or creds is nil.

This function does not support setting a universe domain value on the client.

func NewClient

funcNewClient(opts*Options)(*http.Client,error)

NewClient returns a [net/http.Client] that can be used to communicate with aGoogle cloud service, configured with the provided [Options]. Itautomatically appends Authorization headers to all outgoing requests.

func SetAuthHeader

funcSetAuthHeader(token*auth.Token,req*http.Request)

SetAuthHeader uses the provided token to set the Authorization and trustboundary headers on an http.Request. If the token.Type is empty, the type isassumed to be Bearer. This is the recommended way to set authorizationheaders on a custom http.Request.

ClientCertProvider

typeClientCertProvider=func(*tls.CertificateRequestInfo)(*tls.Certificate,error)

ClientCertProvider is a function that returns a TLS client certificate to beused when opening TLS connections. It follows the same semantics as[crypto/tls.Config.GetClientCertificate].

InternalOptions

typeInternalOptionsstruct{// EnableJWTWithScope specifies if scope can be used with self-signed JWT.EnableJWTWithScopebool// DefaultAudience specifies a default audience to be used as the audience// field ("aud") for the JWT token authentication.DefaultAudiencestring// DefaultEndpointTemplate combined with UniverseDomain specifies the// default endpoint.DefaultEndpointTemplatestring// DefaultMTLSEndpoint specifies the default mTLS endpoint.DefaultMTLSEndpointstring// DefaultScopes specifies the default OAuth2 scopes to be used for a// service.DefaultScopes[]string// SkipValidation bypasses validation on Options. It should only be used// internally for clients that need more control over their transport.SkipValidationbool// SkipUniverseDomainValidation skips the verification that the universe// domain configured for the client matches the universe domain configured// for the credentials. It should only be used internally for clients that// need more control over their transport. The default is false.SkipUniverseDomainValidationbool}

InternalOptions are only meant to be set by generated client code. These arenot meant to be set directly by consumers of this package. Configuration inthis type is considered EXPERIMENTAL and may be removed at any time in thefuture without warning.

Options

typeOptionsstruct{// DisableTelemetry disables default telemetry (OpenTelemetry). An example// reason to do so would be to bind custom telemetry that overrides the// defaults.DisableTelemetrybool// 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.DisableAuthenticationbool// Headers are extra HTTP headers that will be appended to every outgoing// request.Headershttp.Header// BaseRoundTripper overrides the base transport used for serving requests.// If specified ClientCertProvider is ignored.BaseRoundTripperhttp.RoundTripper// Endpoint overrides the default endpoint to be used for a service.Endpointstring// APIKey specifies an API key to be used as the basis for authentication.// If set DetectOpts are ignored.APIKeystring// Credentials used to add Authorization header to all requests. If set// DetectOpts are ignored.Credentials*auth.Credentials// 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.ClientCertProviderClientCertProvider// DetectOpts configures settings for detect Application Default// Credentials.DetectOpts*detect.DetectOptions// UniverseDomain is the default service domain for a given Cloud universe.// The default value is "googleapis.com". This is the universe domain// configured for the client, which will be compared to the universe domain// that is separately configured for the credentials.UniverseDomainstring// Logger is used for debug logging. If provided, logging will be enabled// at the loggers configured level. By default logging is disabled unless// enabled by setting GOOGLE_SDK_GO_LOGGING_LEVEL in which case a default// logger will be used. Optional.Logger*slog.Logger// 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].

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.