Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
|
Authentication components for Google Cloud Storage. More...
Classes | |
class | AnonymousCredentials |
A Credentials type representing "anonymous" Google OAuth2.0 credentials. More... | |
class | AuthorizedUserCredentials |
Wrapper class for Google OAuth 2.0 user account credentials. More... | |
class | AuthorizedUserCredentials< storage::internal::CurlRequestBuilder, std::chrono::system_clock > |
struct | AuthorizedUserCredentialsInfo |
Object to hold information used to instantiate an AuthorizedUserCredentials. More... | |
class | ComputeEngineCredentials |
Wrapper class for Google OAuth 2.0 GCE instance service account credentials. More... | |
class | ComputeEngineCredentials< storage::internal::CurlRequestBuilder, std::chrono::system_clock > |
class | Credentials |
Interface for OAuth 2.0 credentials used to access Google Cloud services. More... | |
class | RefreshingCredentialsWrapper |
Wrapper for refreshable parts of a Credentials object. More... | |
class | ServiceAccountCredentials |
Wrapper class for Google OAuth 2.0 service account credentials. More... | |
class | ServiceAccountCredentials< storage::internal::CurlRequestBuilder, std::chrono::system_clock > |
struct | ServiceAccountCredentialsInfo |
Object to hold information used to instantiate an ServiceAccountCredentials. More... | |
struct | ServiceAccountMetadata |
A helper struct that contains service account metadata. More... | |
Enumerations | |
enum class | JwtSigningAlgorithms { RS256 } |
Supported signing algorithms used in JWT auth flows. More... | |
Functions | |
StatusOr< RefreshingCredentialsWrapper::TemporaryToken > | ParseAuthorizedUserRefreshResponse (storage::internal::HttpResponse const &response, std::chrono::system_clock::time_point now) |
Parses a refresh response JSON string into an authorization header. More... | |
StatusOr< AuthorizedUserCredentialsInfo > | ParseAuthorizedUserCredentials (std::string const &content, std::string const &source, std::string const &default_token_uri=google::cloud::oauth2_internal::GoogleOAuthRefreshEndpoint()) |
Parses a user credentials JSON string into an AuthorizedUserCredentialsInfo. More... | |
StatusOr< ServiceAccountMetadata > | ParseMetadataServerResponse (storage::internal::HttpResponse const &response) |
Parses a metadata server response JSON string into a ServiceAccountMetadata. More... | |
StatusOr< RefreshingCredentialsWrapper::TemporaryToken > | ParseComputeEngineRefreshResponse (storage::internal::HttpResponse const &response, std::chrono::system_clock::time_point now) |
Parses a refresh response JSON string into an authorization header. More... | |
constexpr std::chrono::seconds | GoogleOAuthAccessTokenLifetime () |
The max lifetime in seconds of an access token. More... | |
constexpr std::chrono::seconds | GoogleOAuthAccessTokenExpirationSlack () |
Returns the slack to consider when checking if an access token is expired. More... | |
char const * | GoogleOAuthRefreshEndpoint () |
The endpoint to fetch an OAuth 2.0 access token from. More... | |
char const * | GoogleOAuthScopeCloudPlatform () |
String representing the "cloud-platform" OAuth 2.0 scope. More... | |
char const * | GoogleAdcEnvVar () |
Returns the Application Default Credentials environment variable name. More... | |
std::string | GoogleAdcFilePathFromEnvVarOrEmpty () |
Returns the path to the Application Default Credentials file, if set. More... | |
std::string | GoogleAdcFilePathFromWellKnownPathOrEmpty () |
Returns the path to the Application Default Credentials file, if set. More... | |
char const * | GoogleGcloudAdcFileEnvVar () |
Returns the environment variable to override the gcloud ADC path. More... | |
char const * | GoogleAdcHomeEnvVar () |
Returns the environment variable used to construct the well known ADC path. More... | |
StatusOr< std::shared_ptr< Credentials > > | GoogleDefaultCredentials (ChannelOptions const &options={}) |
Produces a Credentials type based on the runtime environment. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromDefaultPaths (ChannelOptions const &options={}) |
Produces a ServiceAccountCredentials type by trying to load the standard Application Default Credentials paths. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromDefaultPaths (absl::optional< std::set< std::string > > scopes, absl::optional< std::string > subject, ChannelOptions const &options={}) |
Produces a ServiceAccountCredentials type by trying to load the standard Application Default Credentials paths. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromJsonContents (std::string const &contents, ChannelOptions const &options={}) |
Creates a ServiceAccountCredentials from a JSON string. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromJsonContents (std::string const &contents, absl::optional< std::set< std::string > > scopes, absl::optional< std::string > subject, ChannelOptions const &options={}) |
Creates a ServiceAccountCredentials from a JSON string. More... | |
std::shared_ptr< Credentials > | CreateComputeEngineCredentials () |
Creates a ComputeEngineCredentials for the VM's default service account. More... | |
std::shared_ptr< Credentials > | CreateComputeEngineCredentials (std::string const &service_account_email) |
Creates a ComputeEngineCredentials for the VM's specified service account. More... | |
StatusOr< ServiceAccountCredentialsInfo > | ParseServiceAccountCredentials (std::string const &content, std::string const &source, std::string const &default_token_uri=GoogleOAuthRefreshEndpoint()) |
Parses the contents of a JSON keyfile into a ServiceAccountCredentialsInfo. More... | |
StatusOr< ServiceAccountCredentialsInfo > | ParseServiceAccountP12File (std::string const &source, std::string const &default_token_uri=GoogleOAuthRefreshEndpoint()) |
Parses the contents of a P12 keyfile into a ServiceAccountCredentialsInfo. More... | |
StatusOr< RefreshingCredentialsWrapper::TemporaryToken > | ParseServiceAccountRefreshResponse (storage::internal::HttpResponse const &response, std::chrono::system_clock::time_point now) |
Parses a refresh response JSON string and uses the current time to create a TemporaryToken. More... | |
std::pair< std::string, std::string > | AssertionComponentsFromInfo (ServiceAccountCredentialsInfo const &info, std::chrono::system_clock::time_point now) |
Splits a ServiceAccountCredentialsInfo into header and payload components and uses the current time to make a JWT assertion. More... | |
std::string | MakeJWTAssertion (std::string const &header, std::string const &payload, std::string const &pem_contents) |
Given a key and a JSON header and payload, creates a JWT assertion string. More... | |
std::string | CreateServiceAccountRefreshPayload (ServiceAccountCredentialsInfo const &info, std::string const &grant_type, std::chrono::system_clock::time_point now) |
Uses a ServiceAccountCredentialsInfo and the current time to construct a JWT assertion. More... | |
StatusOr< std::string > | MakeSelfSignedJWT (ServiceAccountCredentialsInfo const &info, std::chrono::system_clock::time_point tp) |
Make a self-signed JWT from the service account. More... | |
bool | ServiceAccountUseOAuth (ServiceAccountCredentialsInfo const &info) |
Return true if we need to use the OAuth path to create tokens. More... | |
Functions to manually create specific credential types. | |
| |
std::shared_ptr< Credentials > | CreateAnonymousCredentials () |
Creates an AnonymousCredentials. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateAuthorizedUserCredentialsFromJsonFilePath (std::string const &path) |
Creates an AuthorizedUserCredentials from a JSON file at the specified path. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateAuthorizedUserCredentialsFromJsonContents (std::string const &contents, ChannelOptions const &options={}) |
Creates an AuthorizedUserCredentials from a JSON string. More... | |
Load service account key files. | |
| |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromFilePath (std::string const &path) |
Creates a ServiceAccountCredentials from a file at the specified path. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromFilePath (std::string const &path, absl::optional< std::set< std::string > > scopes, absl::optional< std::string > subject) |
Creates a ServiceAccountCredentials from a file at the specified path. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromJsonFilePath (std::string const &path) |
Creates a ServiceAccountCredentials from a JSON file at the specified path. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromJsonFilePath (std::string const &path, absl::optional< std::set< std::string > > scopes, absl::optional< std::string > subject, ChannelOptions const &options={}) |
Creates a ServiceAccountCredentials from a JSON file at the specified path. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromP12FilePath (std::string const &path) |
Creates a ServiceAccountCredentials from a P12 file at the specified path. More... | |
StatusOr< std::shared_ptr< Credentials > > | CreateServiceAccountCredentialsFromP12FilePath (std::string const &path, absl::optional< std::set< std::string > > scopes, absl::optional< std::string > subject, ChannelOptions const &options={}) |
Creates a ServiceAccountCredentials from a P12 file at the specified path. More... | |
Authentication components for Google Cloud Storage.
|
strong |
Supported signing algorithms used in JWT auth flows.
We currently only support RSA with SHA-256, but use this enum for readability and easy addition of support for other algorithms.
Enumerator | |
---|---|
RS256 |
std::pair< std::string, std::string > google::cloud::storage::oauth2::AssertionComponentsFromInfo | ( | ServiceAccountCredentialsInfo const & | info, |
std::chrono::system_clock::time_point | now | ||
) |
Splits a ServiceAccountCredentialsInfo into header and payload components and uses the current time to make a JWT assertion.
std::shared_ptr< Credentials > google::cloud::storage::oauth2::CreateAnonymousCredentials | ( | ) |
Creates an AnonymousCredentials.
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateAuthorizedUserCredentialsFromJsonContents | ( | std::string const & | contents, |
ChannelOptions const & | options = {} |
||
) |
Creates an AuthorizedUserCredentials from a JSON string.
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateAuthorizedUserCredentialsFromJsonFilePath | ( | std::string const & | path | ) |
Creates an AuthorizedUserCredentials from a JSON file at the specified path.
std::shared_ptr< Credentials > google::cloud::storage::oauth2::CreateComputeEngineCredentials | ( | ) |
Creates a ComputeEngineCredentials for the VM's default service account.
std::shared_ptr< Credentials > google::cloud::storage::oauth2::CreateComputeEngineCredentials | ( | std::string const & | service_account_email | ) |
Creates a ComputeEngineCredentials for the VM's specified service account.
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromDefaultPaths | ( | absl::optional< std::set< std::string > > | scopes, |
absl::optional< std::string > | subject, | ||
ChannelOptions const & | options = {} |
||
) |
Produces a ServiceAccountCredentials type by trying to load the standard Application Default Credentials paths.
If the GOOGLE_APPLICATION_CREDENTIALS environment variable is set, the JSON or P12 file it points to will be loaded. Otherwise, if the gcloud utility has configured an Application Default Credentials file, that file is loaded. The loaded file is used to create a ServiceAccountCredentials.
scopes | the scopes to request during the authorization grant. If omitted, the cloud-platform scope, defined by GoogleOAuthScopeCloudPlatform() , is used as a default. |
subject | for domain-wide delegation; the email address of the user for which to request delegated access. If omitted, no "subject" attribute is included in the authorization grant. |
options | any configuration needed for the transport channel to Google's authentication servers. |
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromDefaultPaths | ( | ChannelOptions const & | options = {} | ) |
Produces a ServiceAccountCredentials type by trying to load the standard Application Default Credentials paths.
If the GOOGLE_APPLICATION_CREDENTIALS environment variable is set, the JSON or P12 file it points to will be loaded. Otherwise, if the gcloud utility has configured an Application Default Credentials file, that file is loaded. The loaded file is used to create a ServiceAccountCredentials.
options | any configuration needed for the transport channel to Google's authentication servers. |
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromFilePath | ( | std::string const & | path | ) |
Creates a ServiceAccountCredentials from a file at the specified path.
These credentials use the cloud-platform OAuth 2.0 scope, defined by GoogleOAuthScopeCloudPlatform()
. To specify alternate scopes, use the overloaded version of this function.
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromFilePath | ( | std::string const & | path, |
absl::optional< std::set< std::string > > | scopes, | ||
absl::optional< std::string > | subject | ||
) |
Creates a ServiceAccountCredentials from a file at the specified path.
path | the path to the file containing service account JSON credentials. |
scopes | the scopes to request during the authorization grant. If omitted, the cloud-platform scope, defined by GoogleOAuthScopeCloudPlatform() , is used as a default. |
subject | for domain-wide delegation; the email address of the user for which to request delegated access. If omitted, no "subject" attribute is included in the authorization grant. |
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromJsonContents | ( | std::string const & | contents, |
absl::optional< std::set< std::string > > | scopes, | ||
absl::optional< std::string > | subject, | ||
ChannelOptions const & | options = {} |
||
) |
Creates a ServiceAccountCredentials from a JSON string.
contents | the string containing the JSON contents of a service account credentials file. |
scopes | the scopes to request during the authorization grant. If omitted, the cloud-platform scope, defined by GoogleOAuthScopeCloudPlatform() , is used as a default. |
subject | for domain-wide delegation; the email address of the user for which to request delegated access. If omitted, no "subject" attribute is included in the authorization grant. |
options | any configuration needed for the transport channel to Google's authentication servers. |
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromJsonContents | ( | std::string const & | contents, |
ChannelOptions const & | options = {} |
||
) |
Creates a ServiceAccountCredentials from a JSON string.
These credentials use the cloud-platform OAuth 2.0 scope, defined by GoogleOAuthScopeCloudPlatform()
. To specify an alternate set of scopes, use the overloaded version of this function.
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromJsonFilePath | ( | std::string const & | path | ) |
Creates a ServiceAccountCredentials from a JSON file at the specified path.
These credentials use the cloud-platform OAuth 2.0 scope, defined by GoogleOAuthScopeCloudPlatform()
. To specify alternate scopes, use the overloaded version of this function.
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromJsonFilePath | ( | std::string const & | path, |
absl::optional< std::set< std::string > > | scopes, | ||
absl::optional< std::string > | subject, | ||
ChannelOptions const & | options = {} |
||
) |
Creates a ServiceAccountCredentials from a JSON file at the specified path.
path | the path to the file containing service account JSON credentials. |
scopes | the scopes to request during the authorization grant. If omitted, the cloud-platform scope, defined by GoogleOAuthScopeCloudPlatform() , is used as a default. |
subject | for domain-wide delegation; the email address of the user for which to request delegated access. If omitted, no "subject" attribute is included in the authorization grant. |
options | any configuration needed for the transport channel to Google's authentication servers. |
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromP12FilePath | ( | std::string const & | path | ) |
Creates a ServiceAccountCredentials from a P12 file at the specified path.
These credentials use the cloud-platform OAuth 2.0 scope, defined by GoogleOAuthScopeCloudPlatform()
. To specify alternate scopes, use the overloaded version of this function.
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::CreateServiceAccountCredentialsFromP12FilePath | ( | std::string const & | path, |
absl::optional< std::set< std::string > > | scopes, | ||
absl::optional< std::string > | subject, | ||
ChannelOptions const & | options = {} |
||
) |
Creates a ServiceAccountCredentials from a P12 file at the specified path.
path | the path to the file containing service account JSON credentials. |
scopes | the scopes to request during the authorization grant. If omitted, the cloud-platform scope, defined by GoogleOAuthScopeCloudPlatform() , is used as a default. |
subject | for domain-wide delegation; the email address of the user for which to request delegated access. If omitted, no "subject" attribute is included in the authorization grant. |
options | any configuration needed for the transport channel to Google's authentication servers. |
std::string google::cloud::storage::oauth2::CreateServiceAccountRefreshPayload | ( | ServiceAccountCredentialsInfo const & | info, |
std::string const & | grant_type, | ||
std::chrono::system_clock::time_point | now | ||
) |
Uses a ServiceAccountCredentialsInfo and the current time to construct a JWT assertion.
The assertion combined with the grant type is used to create the refresh payload.
char const * google::cloud::storage::oauth2::GoogleAdcEnvVar | ( | ) |
Returns the Application Default Credentials environment variable name.
This environment variable should be checked for a valid file path when attempting to load Google Application Default Credentials.
std::string google::cloud::storage::oauth2::GoogleAdcFilePathFromEnvVarOrEmpty | ( | ) |
Returns the path to the Application Default Credentials file, if set.
If the Application Default Credentials environment variable is set, we check the path specified by its value for a file containing ADCs. Returns an empty string if no such path exists or the environment variable is not set.
std::string google::cloud::storage::oauth2::GoogleAdcFilePathFromWellKnownPathOrEmpty | ( | ) |
Returns the path to the Application Default Credentials file, if set.
If the gcloud utility has configured an Application Default Credentials file, the path to that file is returned. Returns an empty string if no such file exists at the well known path.
char const * google::cloud::storage::oauth2::GoogleAdcHomeEnvVar | ( | ) |
Returns the environment variable used to construct the well known ADC path.
The directory containing a user's application configuration data, indicated by this environment variable, varies across environments. That directory is used when constructing the well known path of the Application Default Credentials file.
StatusOr< std::shared_ptr< Credentials > > google::cloud::storage::oauth2::GoogleDefaultCredentials | ( | ChannelOptions const & | options = {} | ) |
Produces a Credentials type based on the runtime environment.
If the GOOGLE_APPLICATION_CREDENTIALS environment variable is set, the JSON file it points to will be loaded and used to create a credential of the specified type. Otherwise, if running on a Google-hosted environment (e.g. Compute Engine), credentials for the environment's default service account will be used.
char const * google::cloud::storage::oauth2::GoogleGcloudAdcFileEnvVar | ( | ) |
Returns the environment variable to override the gcloud ADC path.
This environment variable is used for testing to override the path that should be searched for the gcloud Application Default Credentials file.
|
constexpr |
Returns the slack to consider when checking if an access token is expired.
This time should be subtracted from a token's expiration time when checking if it is expired. This prevents race conditions where, for example, one might check expiration time one second before the expiration, see that the token is still valid, then attempt to use it two seconds later and receive an error.
|
constexpr |
The max lifetime in seconds of an access token.
|
inline |
The endpoint to fetch an OAuth 2.0 access token from.
|
inline |
String representing the "cloud-platform" OAuth 2.0 scope.
std::string google::cloud::storage::oauth2::MakeJWTAssertion | ( | std::string const & | header, |
std::string const & | payload, | ||
std::string const & | pem_contents | ||
) |
Given a key and a JSON header and payload, creates a JWT assertion string.
StatusOr< std::string > google::cloud::storage::oauth2::MakeSelfSignedJWT | ( | ServiceAccountCredentialsInfo const & | info, |
std::chrono::system_clock::time_point | tp | ||
) |
Make a self-signed JWT from the service account.
Self-signed JWTs bypass the intermediate step of exchanging client assertions for OAuth tokens. The advantages of self-signed JTWs include:
info | the parsed service account information, see ParseServiceAccountCredentials() |
tp | the current time |
Authorization
header with the "Bearer" type.StatusOr< AuthorizedUserCredentialsInfo > google::cloud::storage::oauth2::ParseAuthorizedUserCredentials | ( | std::string const & | content, |
std::string const & | source, | ||
std::string const & | default_token_uri = google::cloud::oauth2_internal::GoogleOAuthRefreshEndpoint() |
||
) |
Parses a user credentials JSON string into an AuthorizedUserCredentialsInfo.
StatusOr< RefreshingCredentialsWrapper::TemporaryToken > google::cloud::storage::oauth2::ParseAuthorizedUserRefreshResponse | ( | storage::internal::HttpResponse const & | response, |
std::chrono::system_clock::time_point | now | ||
) |
Parses a refresh response JSON string into an authorization header.
The header and the current time (for the expiration) form a TemporaryToken.
StatusOr< RefreshingCredentialsWrapper::TemporaryToken > google::cloud::storage::oauth2::ParseComputeEngineRefreshResponse | ( | storage::internal::HttpResponse const & | response, |
std::chrono::system_clock::time_point | now | ||
) |
Parses a refresh response JSON string into an authorization header.
The header and the current time (for the expiration) form a TemporaryToken.
StatusOr< ServiceAccountMetadata > google::cloud::storage::oauth2::ParseMetadataServerResponse | ( | storage::internal::HttpResponse const & | response | ) |
Parses a metadata server response JSON string into a ServiceAccountMetadata.
StatusOr< ServiceAccountCredentialsInfo > google::cloud::storage::oauth2::ParseServiceAccountCredentials | ( | std::string const & | content, |
std::string const & | source, | ||
std::string const & | default_token_uri = GoogleOAuthRefreshEndpoint() |
||
) |
Parses the contents of a JSON keyfile into a ServiceAccountCredentialsInfo.
StatusOr< ServiceAccountCredentialsInfo > google::cloud::storage::oauth2::ParseServiceAccountP12File | ( | std::string const & | source, |
std::string const & | default_token_uri = GoogleOAuthRefreshEndpoint() |
||
) |
Parses the contents of a P12 keyfile into a ServiceAccountCredentialsInfo.
client_email
for the service account, the application must obtain this through some other means and provide them to the function.StatusOr< RefreshingCredentialsWrapper::TemporaryToken > google::cloud::storage::oauth2::ParseServiceAccountRefreshResponse | ( | storage::internal::HttpResponse const & | response, |
std::chrono::system_clock::time_point | now | ||
) |
Parses a refresh response JSON string and uses the current time to create a TemporaryToken.
bool google::cloud::storage::oauth2::ServiceAccountUseOAuth | ( | ServiceAccountCredentialsInfo const & | info | ) |
Return true if we need to use the OAuth path to create tokens.