JWTTokenURL is Google's OAuth 2.0 token URL to use with the JWT flow.
const JWTTokenURL = "https://oauth2.googleapis.com/token"
MTLSTokenURL is Google's OAuth 2.0 default mTLS endpoint.
const MTLSTokenURL = "https://oauth2.mtls.googleapis.com/token"
Endpoint is Google's OAuth 2.0 default endpoint.
var Endpoint = oauth2.Endpoint{ AuthURL: "https://accounts.google.com/o/oauth2/auth", TokenURL: "https://oauth2.googleapis.com/token", DeviceAuthURL: "https://oauth2.googleapis.com/device/code", AuthStyle: oauth2.AuthStyleInParams, }
func AppEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSource
AppEngineTokenSource returns a token source that fetches tokens from either the current application's service account or from the metadata server, depending on the App Engine environment. See below for environment-specific details. If you are implementing a 3-legged OAuth 2.0 flow on App Engine that involves user accounts, see oauth2.Config instead.
The current version of this library requires at least Go 1.17 to build, so first generation App Engine runtimes (<= Go 1.9) are unsupported. Previously, on first generation App Engine runtimes, AppEngineTokenSource returned a token source that fetches tokens issued to the current App Engine application's service account. The provided context must have come from appengine.NewContext.
Second generation App Engine runtimes (>= Go 1.11) and App Engine flexible: AppEngineTokenSource is DEPRECATED on second generation runtimes and on the flexible environment. It delegates to ComputeTokenSource, and the provided context and scopes are not used. Please use DefaultTokenSource (or ComputeTokenSource, which DefaultTokenSource will use in this case) instead.
func ComputeTokenSource(account string, scope ...string) oauth2.TokenSource
ComputeTokenSource returns a token source that fetches access tokens from Google Compute Engine (GCE)'s metadata server. It's only valid to use this token source if your program is running on a GCE instance. If no account is specified, "default" is used. If no scopes are specified, a set of default scopes are automatically granted. Further information about retrieving access tokens from the GCE metadata server can be found at https://cloud.google.com/compute/docs/authentication.
▹ Example
func ConfigFromJSON(jsonKey []byte, scope ...string) (*oauth2.Config, error)
ConfigFromJSON uses a Google Developers Console client_credentials.json file to construct a config. client_credentials.json can be downloaded from https://console.developers.google.com, under "Credentials". Download the Web application credentials in the JSON format and provide the contents of the file as jsonKey.
func DefaultClient(ctx context.Context, scope ...string) (*http.Client, error)
DefaultClient returns an HTTP Client that uses the DefaultTokenSource to obtain authentication credentials.
▹ Example
func DefaultTokenSource(ctx context.Context, scope ...string) (oauth2.TokenSource, error)
DefaultTokenSource returns the token source for "Application Default Credentials". It is a shortcut for FindDefaultCredentials(ctx, scope).TokenSource.
func JWTAccessTokenSourceFromJSON(jsonKey []byte, audience string) (oauth2.TokenSource, error)
JWTAccessTokenSourceFromJSON uses a Google Developers service account JSON key file to read the credentials that authorize and authenticate the requests, and returns a TokenSource that does not use any OAuth2 flow but instead creates a JWT and sends that as the access token. The audience is typically a URL that specifies the scope of the credentials.
Note that this is not a standard OAuth flow, but rather an optimization supported by a few Google services. Unless you know otherwise, you should use JWTConfigFromJSON instead.
func JWTAccessTokenSourceWithScope(jsonKey []byte, scope ...string) (oauth2.TokenSource, error)
JWTAccessTokenSourceWithScope uses a Google Developers service account JSON key file to read the credentials that authorize and authenticate the requests, and returns a TokenSource that does not use any OAuth2 flow but instead creates a JWT and sends that as the access token. The scope is typically a list of URLs that specifies the scope of the credentials.
Note that this is not a standard OAuth flow, but rather an optimization supported by a few Google services. Unless you know otherwise, you should use JWTConfigFromJSON instead.
func JWTConfigFromJSON(jsonKey []byte, scope ...string) (*jwt.Config, error)
JWTConfigFromJSON uses a Google Developers service account JSON key file to read the credentials that authorize and authenticate the requests. Create a service account on "Credentials" for your project at https://console.developers.google.com to download a JSON key file.
▹ Example
AuthenticationError indicates there was an error in the authentication flow.
Use (*AuthenticationError).Temporary to check if the error can be retried.
type AuthenticationError struct {
// contains filtered or unexported fields
}
func (e *AuthenticationError) Error() string
func (e *AuthenticationError) Temporary() bool
Temporary indicates that the network error has one of the following status codes and may be retried: 500, 503, 408, or 429.
func (e *AuthenticationError) Unwrap() error
Credentials holds Google credentials, including "Application Default Credentials". For more details, see: https://developers.google.com/accounts/docs/application-default-credentials Credentials from external accounts (workload identity federation) are used to identify a particular application from an on-prem or non-Google Cloud platform including Amazon Web Services (AWS), Microsoft Azure or any identity provider that supports OpenID Connect (OIDC).
type Credentials struct { ProjectID string // may be empty TokenSource oauth2.TokenSource // JSON contains the raw bytes from a JSON credentials file. // This field may be nil if authentication is provided by the // environment and not with a credentials file, e.g. when code is // running on Google Cloud Platform. JSON []byte // UniverseDomainProvider returns the default service domain for a given // Cloud universe. Optional. // // On GCE, UniverseDomainProvider should return the universe domain value // from Google Compute Engine (GCE)'s metadata server. See also [The attached service // account](https://cloud.google.com/docs/authentication/application-default-credentials#attached-sa). // If the GCE metadata server returns a 404 error, the default universe // domain value should be returned. If the GCE metadata server returns an // error other than 404, the error should be returned. UniverseDomainProvider func() (string, error) // contains filtered or unexported fields }
func CredentialsFromJSON(ctx context.Context, jsonData []byte, scopes ...string) (*Credentials, error)
CredentialsFromJSON invokes CredentialsFromJSONWithParams with the specified scopes.
▹ Example
func CredentialsFromJSONWithParams(ctx context.Context, jsonData []byte, params CredentialsParams) (*Credentials, error)
CredentialsFromJSONWithParams obtains Google credentials from a JSON value. The JSON can represent either a Google Developers Console client_credentials.json file (as in ConfigFromJSON), a Google Developers service account key file, a gcloud user credentials file (a.k.a. refresh token JSON), or the JSON configuration file for workload identity federation in non-Google cloud platforms (see https://cloud.google.com/iam/docs/how-to#using-workload-identity-federation).
func FindDefaultCredentials(ctx context.Context, scopes ...string) (*Credentials, error)
FindDefaultCredentials invokes FindDefaultCredentialsWithParams with the specified scopes.
func FindDefaultCredentialsWithParams(ctx context.Context, params CredentialsParams) (*Credentials, error)
FindDefaultCredentialsWithParams searches for "Application Default Credentials".
It looks for credentials in the following places, preferring the first location found:
func (c *Credentials) GetUniverseDomain() (string, error)
GetUniverseDomain returns the default service domain for a given Cloud universe. If present, UniverseDomainProvider will be invoked and its return value will be cached.
The default value is "googleapis.com".
func (c *Credentials) UniverseDomain() string
UniverseDomain returns the default service domain for a given Cloud universe.
The default value is "googleapis.com".
Deprecated: Use instead (*Credentials).GetUniverseDomain(), which supports obtaining the universe domain when authenticating via the GCE metadata server. Unlike GetUniverseDomain, this method, UniverseDomain, will always return the default value when authenticating via the GCE metadata server. See also [The attached service account](https://cloud.google.com/docs/authentication/application-default-credentials#attached-sa).
CredentialsParams holds user supplied parameters that are used together with a credentials file for building a Credentials object.
type CredentialsParams struct { // Scopes is the list OAuth scopes. Required. // Example: https://www.googleapis.com/auth/cloud-platform Scopes []string // Subject is the user email used for domain wide delegation (see // https://developers.google.com/identity/protocols/oauth2/service-account#delegatingauthority). // Optional. Subject string // AuthHandler is the AuthorizationHandler used for 3-legged OAuth flow. Required for 3LO flow. AuthHandler authhandler.AuthorizationHandler // State is a unique string used with AuthHandler. Required for 3LO flow. State string // PKCE is used to support PKCE flow. Optional for 3LO flow. PKCE *authhandler.PKCEParams // The OAuth2 TokenURL default override. This value overrides the default TokenURL, // unless explicitly specified by the credentials config file. Optional. TokenURL string // EarlyTokenRefresh is the amount of time before a token expires that a new // token will be preemptively fetched. If unset the default value is 10 // seconds. // // Note: This option is currently only respected when using credentials // fetched from the GCE metadata server. EarlyTokenRefresh time.Duration // UniverseDomain is the default service domain for a given Cloud universe. // Only supported in authentication flows that support universe domains. // This value takes precedence over a universe domain explicitly specified // in a credentials config file or by the GCE metadata server. Optional. UniverseDomain string }
DefaultCredentials is the old name of Credentials.
Deprecated: use Credentials instead.
type DefaultCredentials = Credentials
An SDKConfig provides access to tokens from an account already authorized via the Google Cloud SDK.
type SDKConfig struct {
// contains filtered or unexported fields
}
▹ Example
func NewSDKConfig(account string) (*SDKConfig, error)
NewSDKConfig creates an SDKConfig for the given Google Cloud SDK account. If account is empty, the account currently active in Google Cloud SDK properties is used. Google Cloud SDK credentials must be created by running `gcloud auth` before using this function. The Google Cloud SDK is available at https://cloud.google.com/sdk/.
func (c *SDKConfig) Client(ctx context.Context) *http.Client
Client returns an HTTP client using Google Cloud SDK credentials to authorize requests. The token will auto-refresh as necessary. The underlying http.RoundTripper will be obtained using the provided context. The returned client and its Transport should not be modified.
func (c *SDKConfig) Scopes() []string
Scopes are the OAuth 2.0 scopes the current account is authorized for.
func (c *SDKConfig) TokenSource(ctx context.Context) oauth2.TokenSource
TokenSource returns an oauth2.TokenSource that retrieve tokens from Google Cloud SDK credentials using the provided context. It will returns the current access token stored in the credentials, and refresh it when it expires, but it won't update the credentials with the new access token.
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 sources that can be used to access Google Cloud resources from external identity providers. |