Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
Loading...
Searching...
No Matches
google_credentials.h
1// Copyright 2018 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_GOOGLE_CREDENTIALS_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_GOOGLE_CREDENTIALS_H
17
18#include "google/cloud/storage/client_options.h"
19#include "google/cloud/storage/oauth2/credentials.h"
20#include "google/cloud/storage/version.h"
21#include "google/cloud/optional.h"
22#include "absl/types/optional.h"
23#include <memory>
24#include <set>
25#include <string>
26
27namespace google {
28namespace cloud {
29namespace storage {
30GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
31namespace oauth2 {
32
33/**
34 * Produces a Credentials type based on the runtime environment.
35 *
36 * If the GOOGLE_APPLICATION_CREDENTIALS environment variable is set, the JSON
37 * file it points to will be loaded and used to create a credential of the
38 * specified type. Otherwise, if running on a Google-hosted environment (e.g.
39 * Compute Engine), credentials for the environment's default service
40 * account will be used.
41 *
42 * @see https://cloud.google.com/docs/authentication/production for details
43 * about Application Default %Credentials.
44 *
45 * @deprecated Prefer using the unified credentials documented in @ref guac
46 */
47StatusOr<std::shared_ptr<Credentials>> GoogleDefaultCredentials(
48 ChannelOptions const& options = {});
49
50///@{
51/**
52 * @name Functions to manually create specific credential types.
53 *
54 * @deprecated Prefer using the unified credentials documented in @ref guac
55 */
56
57/**
58 * Creates an AnonymousCredentials.
59 *
60 * @deprecated Prefer using the unified credentials documented in @ref guac
61 */
63
64/**
65 * Creates an AuthorizedUserCredentials from a JSON file at the specified path.
66 *
67 * @note It is strongly preferred to instead use service account credentials
68 * with Cloud Storage client libraries.
69 *
70 * @deprecated Prefer using the unified credentials documented in @ref guac
71 */
72StatusOr<std::shared_ptr<Credentials>>
74
75/**
76 * Creates an AuthorizedUserCredentials from a JSON string.
77 *
78 * @note It is strongly preferred to instead use service account credentials
79 * with Cloud Storage client libraries.
80 *
81 * @deprecated Prefer using the unified credentials documented in @ref guac
82 */
83StatusOr<std::shared_ptr<Credentials>>
85 std::string const& contents, ChannelOptions const& options = {});
86
87///@{
88/**
89 * @name Load service account key files.
90 *
91 * @deprecated Prefer using the unified credentials documented in @ref guac
92 */
93
94/**
95 * Creates a ServiceAccountCredentials from a file at the specified path.
96 *
97 * @note This function automatically detects if the file is a JSON or P12 (aka
98 * PFX aka PKCS#12) file and tries to load the file as a service account
99 * credential. We strongly recommend that applications use JSON files for
100 * service account key files.
101 *
102 * These credentials use the cloud-platform OAuth 2.0 scope, defined by
103 * `GoogleOAuthScopeCloudPlatform()`. To specify alternate scopes, use the
104 * overloaded version of this function.
105 *
106 * @deprecated Prefer using the unified credentials documented in @ref guac
107 */
108StatusOr<std::shared_ptr<Credentials>>
109CreateServiceAccountCredentialsFromFilePath(std::string const& path);
110
111/**
112 * Creates a ServiceAccountCredentials from a file at the specified path.
113 *
114 * @note This function automatically detects if the file is a JSON or P12 (aka
115 * PFX aka PKCS#12) file and tries to load the file as a service account
116 * credential. We strongly recommend that applications use JSON files for
117 * service account key files.
118 *
119 * @param path the path to the file containing service account JSON credentials.
120 * @param scopes the scopes to request during the authorization grant. If
121 * omitted, the cloud-platform scope, defined by
122 * `GoogleOAuthScopeCloudPlatform()`, is used as a default.
123 * @param subject for domain-wide delegation; the email address of the user for
124 * which to request delegated access. If omitted, no "subject" attribute is
125 * included in the authorization grant.
126 *
127 * @see https://developers.google.com/identity/protocols/googlescopes for a list
128 * of OAuth 2.0 scopes used with Google APIs.
129 *
130 * @see https://developers.google.com/identity/protocols/OAuth2ServiceAccount
131 * for more information about domain-wide delegation.
132 *
133 * @deprecated Prefer using the unified credentials documented in @ref guac
134 */
135StatusOr<std::shared_ptr<Credentials>>
137 std::string const& path, absl::optional<std::set<std::string>> scopes,
138 absl::optional<std::string> subject);
139
140/**
141 * Creates a ServiceAccountCredentials from a JSON file at the specified path.
142 *
143 * These credentials use the cloud-platform OAuth 2.0 scope, defined by
144 * `GoogleOAuthScopeCloudPlatform()`. To specify alternate scopes, use the
145 * overloaded version of this function.
146 *
147 * @deprecated Prefer using the unified credentials documented in @ref guac
148 */
149StatusOr<std::shared_ptr<Credentials>>
151
152/**
153 * Creates a ServiceAccountCredentials from a JSON file at the specified path.
154 *
155 * @param path the path to the file containing service account JSON credentials.
156 * @param scopes the scopes to request during the authorization grant. If
157 * omitted, the cloud-platform scope, defined by
158 * `GoogleOAuthScopeCloudPlatform()`, is used as a default.
159 * @param subject for domain-wide delegation; the email address of the user for
160 * which to request delegated access. If omitted, no "subject" attribute is
161 * included in the authorization grant.
162 * @param options any configuration needed for the transport channel to
163 * Google's authentication servers.
164 *
165 * @see https://developers.google.com/identity/protocols/googlescopes for a list
166 * of OAuth 2.0 scopes used with Google APIs.
167 *
168 * @see https://developers.google.com/identity/protocols/OAuth2ServiceAccount
169 * for more information about domain-wide delegation.
170 *
171 * @deprecated Prefer using the unified credentials documented in @ref guac
172 */
173StatusOr<std::shared_ptr<Credentials>>
175 std::string const& path, absl::optional<std::set<std::string>> scopes,
176 absl::optional<std::string> subject, ChannelOptions const& options = {});
177
178/**
179 * Creates a ServiceAccountCredentials from a P12 file at the specified path.
180 *
181 * These credentials use the cloud-platform OAuth 2.0 scope, defined by
182 * `GoogleOAuthScopeCloudPlatform()`. To specify alternate scopes, use the
183 * overloaded version of this function.
184 *
185 * @deprecated Prefer using the unified credentials documented in @ref guac
186 */
187StatusOr<std::shared_ptr<Credentials>>
189
190/**
191 * Creates a ServiceAccountCredentials from a P12 file at the specified path.
192 *
193 * @param path the path to the file containing service account JSON credentials.
194 * @param scopes the scopes to request during the authorization grant. If
195 * omitted, the cloud-platform scope, defined by
196 * `GoogleOAuthScopeCloudPlatform()`, is used as a default.
197 * @param subject for domain-wide delegation; the email address of the user for
198 * which to request delegated access. If omitted, no "subject" attribute is
199 * included in the authorization grant.
200 * @param options any configuration needed for the transport channel to
201 * Google's authentication servers.
202 *
203 * @see https://developers.google.com/identity/protocols/googlescopes for a list
204 * of OAuth 2.0 scopes used with Google APIs.
205 *
206 * @see https://developers.google.com/identity/protocols/OAuth2ServiceAccount
207 * for more information about domain-wide delegation.
208 *
209 * @deprecated Prefer using the unified credentials documented in @ref guac
210 */
211StatusOr<std::shared_ptr<Credentials>>
213 std::string const& path, absl::optional<std::set<std::string>> scopes,
214 absl::optional<std::string> subject, ChannelOptions const& options = {});
215///@}
216
217/**
218 * Produces a ServiceAccountCredentials type by trying to load the standard
219 * Application Default %Credentials paths.
220 *
221 * If the GOOGLE_APPLICATION_CREDENTIALS environment variable is set, the JSON
222 * or P12 file it points to will be loaded. Otherwise, if the gcloud utility
223 * has configured an Application Default %Credentials file, that file is
224 * loaded. The loaded file is used to create a ServiceAccountCredentials.
225 *
226 * @param options any configuration needed for the transport channel to
227 * Google's authentication servers.
228 *
229 * @see https://cloud.google.com/docs/authentication/production for details
230 * about Application Default %Credentials.
231 *
232 * @deprecated Prefer using the unified credentials documented in @ref guac
233 */
234StatusOr<std::shared_ptr<Credentials>>
236 ChannelOptions const& options = {});
237
238/**
239 * Produces a ServiceAccountCredentials type by trying to load the standard
240 * Application Default %Credentials paths.
241 *
242 * If the GOOGLE_APPLICATION_CREDENTIALS environment variable is set, the JSON
243 * or P12 file it points to will be loaded. Otherwise, if the gcloud utility
244 * has configured an Application Default %Credentials file, that file is
245 * loaded. The loaded file is used to create a ServiceAccountCredentials.
246 *
247 * @param scopes the scopes to request during the authorization grant. If
248 * omitted, the cloud-platform scope, defined by
249 * `GoogleOAuthScopeCloudPlatform()`, is used as a default.
250 * @param subject for domain-wide delegation; the email address of the user for
251 * which to request delegated access. If omitted, no "subject" attribute is
252 * included in the authorization grant.
253 * @param options any configuration needed for the transport channel to
254 * Google's authentication servers.
255 *
256 * @see https://developers.google.com/identity/protocols/googlescopes for a list
257 * of OAuth 2.0 scopes used with Google APIs.
258 *
259 * @see https://cloud.google.com/docs/authentication/production for details
260 * about Application Default %Credentials.
261 *
262 * @deprecated Prefer using the unified credentials documented in @ref guac
263 */
264StatusOr<std::shared_ptr<Credentials>>
266 absl::optional<std::set<std::string>> scopes,
267 absl::optional<std::string> subject, ChannelOptions const& options = {});
268
269/**
270 * Creates a ServiceAccountCredentials from a JSON string.
271 *
272 * These credentials use the cloud-platform OAuth 2.0 scope, defined by
273 * `GoogleOAuthScopeCloudPlatform()`. To specify an alternate set of scopes, use
274 * the overloaded version of this function.
275 *
276 * @deprecated Prefer using the unified credentials documented in @ref guac
277 */
278StatusOr<std::shared_ptr<Credentials>>
280 std::string const& contents, ChannelOptions const& options = {});
281
282/**
283 * Creates a ServiceAccountCredentials from a JSON string.
284 *
285 * @param contents the string containing the JSON contents of a service account
286 * credentials file.
287 * @param scopes the scopes to request during the authorization grant. If
288 * omitted, the cloud-platform scope, defined by
289 * `GoogleOAuthScopeCloudPlatform()`, is used as a default.
290 * @param subject for domain-wide delegation; the email address of the user for
291 * which to request delegated access. If omitted, no "subject" attribute is
292 * included in the authorization grant.
293 * @param options any configuration needed for the transport channel to
294 * Google's authentication servers.
295 *
296 * @see https://developers.google.com/identity/protocols/googlescopes for a list
297 * of OAuth 2.0 scopes used with Google APIs.
298 *
299 * @see https://developers.google.com/identity/protocols/OAuth2ServiceAccount
300 * for more information about domain-wide delegation.
301 *
302 * @deprecated Prefer using the unified credentials documented in @ref guac
303 */
304StatusOr<std::shared_ptr<Credentials>>
306 std::string const& contents, absl::optional<std::set<std::string>> scopes,
307 absl::optional<std::string> subject, ChannelOptions const& options = {});
308
309/**
310 * Creates a ComputeEngineCredentials for the VM's default service account.
311 *
312 * @deprecated Prefer using the unified credentials documented in @ref guac
313 */
315
316/**
317 * Creates a ComputeEngineCredentials for the VM's specified service account.
318 *
319 * @deprecated Prefer using the unified credentials documented in @ref guac
320 */
322 std::string const& service_account_email);
323
324///@}
325
326} // namespace oauth2
327GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
328} // namespace storage
329} // namespace cloud
330} // namespace google
331
332#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_GOOGLE_CREDENTIALS_H
Describes the configuration for low-level connection features.
Definition: client_options.h:74
Interface for OAuth 2.0 credentials used to access Google Cloud services.
Definition: credentials.h:47
Authentication components for Google Cloud Storage.
Definition: anonymous_credentials.h:26
StatusOr< std::shared_ptr< Credentials > > CreateServiceAccountCredentialsFromP12FilePath(std::string const &path)
Creates a ServiceAccountCredentials from a P12 file at the specified path.
StatusOr< std::shared_ptr< Credentials > > CreateServiceAccountCredentialsFromDefaultPaths(ChannelOptions const &options={})
Produces a ServiceAccountCredentials type by trying to load the standard Application Default Credenti...
StatusOr< std::shared_ptr< Credentials > > GoogleDefaultCredentials(ChannelOptions const &options={})
Produces a Credentials type based on the runtime environment.
std::shared_ptr< Credentials > CreateAnonymousCredentials()
Creates an AnonymousCredentials.
std::shared_ptr< Credentials > CreateComputeEngineCredentials()
Creates a ComputeEngineCredentials for the VM's default service account.
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.
std::shared_ptr< Credentials > CreateComputeEngineCredentials(std::string const &service_account_email)
Creates a ComputeEngineCredentials for the VM's specified service account.
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.
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 Credenti...
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.
StatusOr< std::shared_ptr< Credentials > > CreateServiceAccountCredentialsFromJsonFilePath(std::string const &path)
Creates a ServiceAccountCredentials from a JSON file at the specified path.
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.
StatusOr< std::shared_ptr< Credentials > > CreateServiceAccountCredentialsFromFilePath(std::string const &path)
Creates a ServiceAccountCredentials from a file at the specified path.
StatusOr< std::shared_ptr< Credentials > > CreateAuthorizedUserCredentialsFromJsonFilePath(std::string const &path)
Creates an AuthorizedUserCredentials from a JSON file at the specified path.
StatusOr< std::shared_ptr< Credentials > > CreateServiceAccountCredentialsFromJsonContents(std::string const &contents, ChannelOptions const &options={})
Creates a ServiceAccountCredentials from a JSON string.
StatusOr< std::shared_ptr< Credentials > > CreateAuthorizedUserCredentialsFromJsonContents(std::string const &contents, ChannelOptions const &options={})
Creates an AuthorizedUserCredentials from a JSON string.
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24