func DetectDefault(opts *DetectOptions) (*auth.Credentials, error)
DetectDefault searches for "Application Default Credentials" and returns a credential based on the DetectOptions provided.
It looks for credentials in the following places, preferring the first location found:
▹ Example
▹ Example (WithFilepath)
▹ Example (WithJSON)
func OnGCE() bool
OnGCE reports whether this process is running in Google Cloud.
DetectOptions provides configuration for DetectDefault.
type DetectOptions struct { // Scopes that credentials tokens should have. Example: // https://www.googleapis.com/auth/cloud-platform. Required if Audience is // not provided. Scopes []string // Audience that credentials tokens should have. Only applicable for 2LO // flows with service accounts. If specified, scopes should not be provided. Audience string // Subject is the user email used for [domain wide delegation](https://developers.google.com/identity/protocols/oauth2/service-account#delegatingauthority). // Optional. Subject string // EarlyTokenRefresh configures how early before a token expires that it // should be refreshed. EarlyTokenRefresh time.Duration // AuthHandlerOptions configures an authorization handler and other options // for 3LO flows. It is required, and only used, for client credential // flows. AuthHandlerOptions *auth.AuthorizationHandlerOptions // TokenURL allows to set the token endpoint for user credential flows. If // unset the default value is: https://oauth2.googleapis.com/token. // Optional. TokenURL string // STSAudience is the audience sent to when retrieving an STS token. // Currently this only used for GDCH auth flow, for which it is required. STSAudience string // CredentialsFile overrides detection logic and sources a credential file // from the provided filepath. If provided, CredentialsJSON must not be. // Optional. CredentialsFile string // CredentialsJSON overrides detection logic and uses the JSON bytes as the // source for the credential. If provided, CredentialsFile must not be. // Optional. CredentialsJSON []byte // UseSelfSignedJWT directs service account based credentials to create a // self-signed JWT with the private key found in the file, skipping any // network requests that would normally be made. Optional. UseSelfSignedJWT bool // Client configures the underlying client used to make network requests // when fetching tokens. Optional. Client *http.Client // UniverseDomain is the default service domain for a given Cloud universe. // The default value is "googleapis.com". This option is ignored for // authentication flows that do not support universe domain. Optional. UniverseDomain string }
Name | Synopsis |
---|---|
.. | |
downscope | Package downscope implements the ability to downscope, or restrict, the Identity and Access Management permissions that a short-lived Token can use. |
externalaccount | Package externalaccount provides support for creating workload identity federation and workforce identity federation token providers that can be used to access Google Cloud resources from external identity providers. |
idtoken | |
impersonate | Package impersonate is used to impersonate Google Credentials. |