Showing content from http://cloud.google.com/cpp/docs/reference/storage/latest/storage-auth-example below:
C++ Client Libraries | Google Cloud
Skip to main content
- Overview
-
Library reference docs
- Google Cloud Storage C++ Client Library
-
Namespaces
-
google::cloud::storage
- Overview
-
Classes
-
Functions
- PublicAccessPreventionEnforced()
- PublicAccessPreventionInherited()
- PublicAccessPreventionUnspecified()
- TEAM_EDITORS()
- TEAM_OWNERS()
- TEAM_VIEWERS()
- AutoFinalizeEnabled()
- AutoFinalizeDisabled()
- RpoDefault()
- RpoAsyncTurbo()
- CreateRandomPrefixName(std::string const &)
- DeleteByPrefix(Client &, std::string const &, std::string const &, Options &&...)
- ComposeMany(Client &, std::string const &, std::vector< ComposeSourceObject >, std::string const &, std::string, bool, Options &&...)
- MakeGrpcClient(Options)
- ComputeMD5Hash(absl::string_view)
- ComputeMD5Hash(std::string const &)
- ComputeMD5Hash(char const *)
- EnableMD5Hash()
- ComputeCrc32cChecksum(absl::string_view)
- ComputeCrc32cChecksum(std::string const &)
- ComputeCrc32cChecksum(char const *)
- ObjectRetentionUnlocked()
- ObjectRetentionLocked()
- ParallelUploadFile(Client, std::string, std::string, std::string, std::string, bool, Options &&...)
- FormatDateForForm(PolicyDocumentV4Result const &)
- AddExtensionHeader(std::string, std::string)
- WithGeneration(std::uint64_t)
- WithGenerationMarker(std::uint64_t)
- WithUserProject(std::string)
- WithMarker(std::string)
- WithResponseContentDisposition(std::string)
- WithResponseContentType(std::string const &)
- WithAcl()
- WithBilling()
- WithCompose()
- WithCors()
- WithEncryption()
- WithEncryptionConfig()
- WithLifecycle()
- WithLocation()
- WithLogging()
- WithStorageClass()
- WithTagging()
- AddExtensionField(std::string, std::string)
- RestoreResumableUploadSession(std::string)
- NewResumableUploadSession()
- version_major()
- version_minor()
- version_patch()
- version_pre_release()
- version()
- version_string()
- x_goog_api_client()
- EncryptionDataFromBinaryKey(std::string const &)
- EncryptionDataFromBase64Key(std::string const &)
- CreateKeyFromGenerator(Generator &)
- AcceptEncodingGzip()
- AcceptEncodingIdentity()
-
Operators
- operator==(CorsEntry const &, CorsEntry const &)
- operator<(CorsEntry const &, CorsEntry const &)
- operator!=(CorsEntry const &, CorsEntry const &)
- operator>(CorsEntry const &, CorsEntry const &)
- operator<=(CorsEntry const &, CorsEntry const &)
- operator>=(CorsEntry const &, CorsEntry const &)
- operator==(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator<(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator!=(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator>(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator<=(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator>=(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator==(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator<(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator!=(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator>(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator<=(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator>=(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator==(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator<(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator!=(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator>(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator<=(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator>=(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator==(BucketLifecycle const &, BucketLifecycle const &)
- operator<(BucketLifecycle const &, BucketLifecycle const &)
- operator!=(BucketLifecycle const &, BucketLifecycle const &)
- operator>(BucketLifecycle const &, BucketLifecycle const &)
- operator<=(BucketLifecycle const &, BucketLifecycle const &)
- operator>=(BucketLifecycle const &, BucketLifecycle const &)
- operator<<(std::ostream &, AutoFinalize const &)
- operator<<(std::ostream &, BucketAccessControl const &)
- operator==(BucketAutoclass const &, BucketAutoclass const &)
- operator!=(BucketAutoclass const &, BucketAutoclass const &)
- operator<<(std::ostream &, BucketAutoclass const &)
- operator==(BucketBilling const &, BucketBilling const &)
- operator<(BucketBilling const &, BucketBilling const &)
- operator!=(BucketBilling const &, BucketBilling const &)
- operator>(BucketBilling const &, BucketBilling const &)
- operator<=(BucketBilling const &, BucketBilling const &)
- operator>=(BucketBilling const &, BucketBilling const &)
- operator<<(std::ostream &, CorsEntry const &)
- operator<<(std::ostream &, BucketCustomPlacementConfig const &)
- operator==(BucketEncryption const &, BucketEncryption const &)
- operator<(BucketEncryption const &, BucketEncryption const &)
- operator!=(BucketEncryption const &, BucketEncryption const &)
- operator>(BucketEncryption const &, BucketEncryption const &)
- operator<=(BucketEncryption const &, BucketEncryption const &)
- operator>=(BucketEncryption const &, BucketEncryption const &)
- operator==(BucketHierarchicalNamespace const &, BucketHierarchicalNamespace const &)
- operator!=(BucketHierarchicalNamespace const &, BucketHierarchicalNamespace const &)
- operator<<(std::ostream &, BucketHierarchicalNamespace const &)
- operator<<(std::ostream &, UniformBucketLevelAccess const &)
- operator<<(std::ostream &, BucketIamConfiguration const &)
- operator==(BucketLogging const &, BucketLogging const &)
- operator<(BucketLogging const &, BucketLogging const &)
- operator!=(BucketLogging const &, BucketLogging const &)
- operator>(BucketLogging const &, BucketLogging const &)
- operator<=(BucketLogging const &, BucketLogging const &)
- operator>=(BucketLogging const &, BucketLogging const &)
- operator<<(std::ostream &, BucketLogging const &)
- operator<<(std::ostream &, BucketMetadata const &)
- operator==(BucketObjectRetention const &, BucketObjectRetention const &)
- operator!=(BucketObjectRetention const &, BucketObjectRetention const &)
- operator<<(std::ostream &, BucketObjectRetention const &)
- operator==(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator<(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator!=(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator>(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator<=(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator>=(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator<<(std::ostream &, BucketRetentionPolicy const &)
- operator==(BucketSoftDeletePolicy const &, BucketSoftDeletePolicy const &)
- operator!=(BucketSoftDeletePolicy const &, BucketSoftDeletePolicy const &)
- operator<<(std::ostream &, BucketSoftDeletePolicy const &)
- operator==(BucketVersioning const &, BucketVersioning const &)
- operator<(BucketVersioning const &, BucketVersioning const &)
- operator!=(BucketVersioning const &, BucketVersioning const &)
- operator>(BucketVersioning const &, BucketVersioning const &)
- operator<=(BucketVersioning const &, BucketVersioning const &)
- operator>=(BucketVersioning const &, BucketVersioning const &)
- operator==(BucketWebsite const &, BucketWebsite const &)
- operator<(BucketWebsite const &, BucketWebsite const &)
- operator!=(BucketWebsite const &, BucketWebsite const &)
- operator>(BucketWebsite const &, BucketWebsite const &)
- operator<=(BucketWebsite const &, BucketWebsite const &)
- operator>=(BucketWebsite const &, BucketWebsite const &)
- operator<<(std::ostream &, ReadRangeData const &)
- operator==(HmacKeyMetadata const &, HmacKeyMetadata const &)
- operator!=(HmacKeyMetadata const &, HmacKeyMetadata const &)
- operator<<(std::ostream &, HmacKeyMetadata const &)
- operator<<(std::ostream &, NativeExpression const &)
- operator<<(std::ostream &, NativeIamBinding const &)
- operator<<(std::ostream &, NativeIamPolicy const &)
- operator==(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator<(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator!=(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator>(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator<=(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator>=(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator<<(std::ostream &, LifecycleRuleAction const &)
- operator==(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator<(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator!=(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator>(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator<=(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator>=(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator<<(std::ostream &, LifecycleRuleCondition const &)
- operator==(LifecycleRule const &, LifecycleRule const &)
- operator<(LifecycleRule const &, LifecycleRule const &)
- operator!=(LifecycleRule const &, LifecycleRule const &)
- operator>(LifecycleRule const &, LifecycleRule const &)
- operator<=(LifecycleRule const &, LifecycleRule const &)
- operator>=(LifecycleRule const &, LifecycleRule const &)
- operator<<(std::ostream &, LifecycleRule const &)
- operator==(NotificationMetadata const &, NotificationMetadata const &)
- operator<(NotificationMetadata const &, NotificationMetadata const &)
- operator!=(NotificationMetadata const &, NotificationMetadata const &)
- operator>(NotificationMetadata const &, NotificationMetadata const &)
- operator<=(NotificationMetadata const &, NotificationMetadata const &)
- operator>=(NotificationMetadata const &, NotificationMetadata const &)
- operator<<(std::ostream &, NotificationMetadata const &)
- operator<<(std::ostream &, ObjectAccessControl const &)
- operator<<(std::ostream &, ComposeSourceObject const &)
- operator==(CustomerEncryption const &, CustomerEncryption const &)
- operator<(CustomerEncryption const &, CustomerEncryption const &)
- operator!=(CustomerEncryption const &, CustomerEncryption const &)
- operator>(CustomerEncryption const &, CustomerEncryption const &)
- operator<=(CustomerEncryption const &, CustomerEncryption const &)
- operator>=(CustomerEncryption const &, CustomerEncryption const &)
- operator<<(std::ostream &, ObjectMetadata const &)
- operator==(ObjectRetention const &, ObjectRetention const &)
- operator!=(ObjectRetention const &, ObjectRetention const &)
- operator<<(std::ostream &, ObjectRetention const &)
- operator==(Owner const &, Owner const &)
- operator<(Owner const &, Owner const &)
- operator!=(Owner const &, Owner const &)
- operator>(Owner const &, Owner const &)
- operator<=(Owner const &, Owner const &)
- operator>=(Owner const &, Owner const &)
- operator==(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator<(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator!=(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator>(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator<=(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator>=(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator<<(std::ostream &, PolicyDocumentCondition const &)
- operator<<(std::ostream &, PolicyDocument const &)
- operator<<(std::ostream &, PolicyDocumentV4 const &)
- operator<<(std::ostream &, PolicyDocumentResult const &)
- operator<<(std::ostream &, PolicyDocumentV4Result const &)
- operator==(ProjectTeam const &, ProjectTeam const &)
- operator<(ProjectTeam const &, ProjectTeam const &)
- operator!=(ProjectTeam const &, ProjectTeam const &)
- operator>(ProjectTeam const &, ProjectTeam const &)
- operator<=(ProjectTeam const &, ProjectTeam const &)
- operator>=(ProjectTeam const &, ProjectTeam const &)
- operator==(ServiceAccount const &, ServiceAccount const &)
- operator<(ServiceAccount const &, ServiceAccount const &)
- operator!=(ServiceAccount const &, ServiceAccount const &)
- operator>(ServiceAccount const &, ServiceAccount const &)
- operator<=(ServiceAccount const &, ServiceAccount const &)
- operator>=(ServiceAccount const &, ServiceAccount const &)
- operator<<(std::ostream &, ServiceAccount const &)
- operator<<(std::ostream &, CustomHeader const &)
- operator<<(std::ostream &, EncryptionKey const &)
- operator<<(std::ostream &, SourceEncryptionKey const &)
-
google::cloud::storage::event_type
-
google::cloud::storage::oauth2
- Overview
-
Classes
-
AuthorizedUserCredentials<HttpRequestBuilderType, ClockType>
-
ComputeEngineCredentials<HttpRequestBuilderType, ClockType>
-
ServiceAccountCredentials<HttpRequestBuilderType, ClockType>
-
Functions
- CreateAnonymousCredentials()
- CreateAuthorizedUserCredentialsFromJsonFilePath(std::string const &)
- CreateAuthorizedUserCredentialsFromJsonContents(std::string const &, ChannelOptions const &)
- CreateServiceAccountCredentialsFromFilePath(std::string const &)
- CreateServiceAccountCredentialsFromFilePath(std::string const &, absl::optional< std::set< std::string > >, absl::optional< std::string >)
- CreateServiceAccountCredentialsFromJsonFilePath(std::string const &)
- CreateServiceAccountCredentialsFromJsonFilePath(std::string const &, absl::optional< std::set< std::string > >, absl::optional< std::string >, ChannelOptions const &)
- CreateServiceAccountCredentialsFromP12FilePath(std::string const &)
- CreateServiceAccountCredentialsFromP12FilePath(std::string const &, absl::optional< std::set< std::string > >, absl::optional< std::string >, ChannelOptions const &)
- ParseAuthorizedUserRefreshResponse(storage::internal::HttpResponse const &, std::chrono::system_clock::time_point)
- ParseAuthorizedUserCredentials(std::string const &, std::string const &, std::string const &)
- ParseMetadataServerResponse(storage::internal::HttpResponse const &)
- ParseComputeEngineRefreshResponse(storage::internal::HttpResponse const &, std::chrono::system_clock::time_point)
- GoogleOAuthAccessTokenLifetime()
- GoogleOAuthAccessTokenExpirationSlack()
- GoogleOAuthRefreshEndpoint()
- GoogleOAuthScopeCloudPlatform()
- GoogleAdcEnvVar()
- GoogleAdcFilePathFromEnvVarOrEmpty()
- GoogleAdcFilePathFromWellKnownPathOrEmpty()
- GoogleGcloudAdcFileEnvVar()
- GoogleAdcHomeEnvVar()
- GoogleDefaultCredentials(ChannelOptions const &)
- CreateServiceAccountCredentialsFromDefaultPaths(ChannelOptions const &)
- CreateServiceAccountCredentialsFromDefaultPaths(absl::optional< std::set< std::string > >, absl::optional< std::string >, ChannelOptions const &)
- CreateServiceAccountCredentialsFromJsonContents(std::string const &, ChannelOptions const &)
- CreateServiceAccountCredentialsFromJsonContents(std::string const &, absl::optional< std::set< std::string > >, absl::optional< std::string >, ChannelOptions const &)
- CreateComputeEngineCredentials()
- CreateComputeEngineCredentials(std::string const &)
- ParseServiceAccountCredentials(std::string const &, std::string const &, std::string const &)
- ParseServiceAccountP12File(std::string const &, std::string const &)
- ParseServiceAccountRefreshResponse(storage::internal::HttpResponse const &, std::chrono::system_clock::time_point)
- AssertionComponentsFromInfo(ServiceAccountCredentialsInfo const &, std::chrono::system_clock::time_point)
- MakeJWTAssertion(std::string const &, std::string const &, std::string const &)
- CreateServiceAccountRefreshPayload(ServiceAccountCredentialsInfo const &, std::string const &, std::chrono::system_clock::time_point)
- MakeSelfSignedJWT(ServiceAccountCredentialsInfo const &, std::chrono::system_clock::time_point)
- ServiceAccountUseOAuth(ServiceAccountCredentialsInfo const &)
-
google::cloud::storage::payload_format
-
google::cloud::storage::storage_class
-
google::cloud::storage_experimental
- Overview
-
Classes
-
AsyncClient
- Overview
-
Functions
- InsertObject(BucketName const &, std::string, Collection &&, Options)
- InsertObject(google::storage::v2::WriteObjectRequest, Collection &&, Options)
- InsertObject(google::storage::v2::WriteObjectRequest, WritePayload, Options)
- Open(BucketName const &, std::string, Options)
- Open(google::storage::v2::BidiReadObjectSpec, Options)
- ReadObject(BucketName const &, std::string, Options)
- ReadObject(google::storage::v2::ReadObjectRequest, Options)
- ReadObjectRange(BucketName const &, std::string, std::int64_t, std::int64_t, Options)
- ReadObjectRange(google::storage::v2::ReadObjectRequest, std::int64_t, std::int64_t, Options)
- StartAppendableObjectUpload(BucketName const &, std::string, Options)
- StartAppendableObjectUpload(google::storage::v2::BidiWriteObjectRequest, Options)
- ResumeAppendableObjectUpload(BucketName const &, std::string, std::int64_t, Options)
- StartBufferedUpload(BucketName const &, std::string, Options)
- StartBufferedUpload(google::storage::v2::StartResumableWriteRequest, Options)
- ResumeBufferedUpload(std::string, Options)
- ResumeBufferedUpload(google::storage::v2::QueryWriteStatusRequest, Options)
- StartUnbufferedUpload(BucketName const &, std::string, Options)
- StartUnbufferedUpload(google::storage::v2::StartResumableWriteRequest, Options)
- ResumeUnbufferedUpload(std::string, Options)
- ResumeUnbufferedUpload(google::storage::v2::QueryWriteStatusRequest, Options)
- ComposeObject(BucketName const &, std::string, std::vector< google::storage::v2::ComposeObjectRequest::SourceObject >, Options)
- ComposeObject(google::storage::v2::ComposeObjectRequest, Options)
- DeleteObject(BucketName const &, std::string, Options)
- DeleteObject(BucketName const &, std::string, std::int64_t, Options)
- DeleteObject(google::storage::v2::DeleteObjectRequest, Options)
- StartRewrite(BucketName const &, std::string, BucketName const &, std::string, Options)
- StartRewrite(google::storage::v2::RewriteObjectRequest, Options)
- ResumeRewrite(BucketName const &, std::string, BucketName const &, std::string, std::string, Options)
- ResumeRewrite(google::storage::v2::RewriteObjectRequest, Options)
-
google::cloud::storage_mocks
Stay organized with collections Save and categorize content based on your preferences.
Override the authentication configuration
Some applications cannot use the default authentication mechanism (known as Application Default Credentials). You can override this default using google::cloud::UnifiedCredentialsOption
. The following example shows how to explicitly load a service account key file.
namespace gcs = ::google::cloud::storage;
[](std::string const& filename, std::string const& bucket_name,
std::string const& object_name) {
auto is = std::ifstream(filename);
is.exceptions(std::ios::badbit);
auto json_string =
std::string(std::istreambuf_iterator<char>(is.rdbuf()), {});
auto credentials =
google::cloud::MakeServiceAccountCredentials(json_string);
auto client = gcs::Client(
google::cloud::Options{}.set<google::cloud::UnifiedCredentialsOption>(
credentials));
PerformSomeOperations(client, bucket_name, object_name);
}
Keep in mind that we chose this as an example because it is relatively easy to understand. Consult the Best practices for managing service account keys guide for more details.
See Also
Authentication Components - for more information on the factory functions to create google::cloud::Credentials
objects.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["The latest version available is 2.37.0-rc, with a history of versions back to 2.11.0 accessible via their respective links."],["The default authentication mechanism, known as Application Default Credentials, can be overridden using `google::cloud::UnifiedCredentialsOption`."],["An example demonstrates loading a service account key file to override the default authentication and set credentials in `google::cloud::Options`."],["Service account keys are used in the example, and it is recommended to consult the best practices guide for managing these keys."],["For more information on the factory functions to create `google::cloud::Credentials` objects, refer to the Authentication Components documentation."]]],[]]
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4