Google Cloud Storage C++ Client  1.42.0
A C++ Client Library for Google Cloud Storage
credentials.h
Go to the documentation of this file.
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_CREDENTIALS_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_CREDENTIALS_H
17 
18 #include "google/cloud/storage/signed_url_options.h"
19 #include "google/cloud/storage/version.h"
20 #include "google/cloud/status.h"
21 #include "google/cloud/status_or.h"
22 #include <string>
23 #include <vector>
24 
25 namespace google {
26 namespace cloud {
27 namespace storage {
29 namespace oauth2 {
30 /**
31  * Interface for OAuth 2.0 credentials used to access Google Cloud services.
32  *
33  * Instantiating a specific kind of `Credentials` should usually be done via the
34  * convenience methods declared in google_credentials.h.
35  *
36  * @see https://cloud.google.com/docs/authentication/ for an overview of
37  * authenticating to Google Cloud Platform APIs.
38  */
39 class Credentials {
40  public:
41  virtual ~Credentials() = default;
42 
43  /**
44  * Attempts to obtain a value for the Authorization HTTP header.
45  *
46  * If unable to obtain a value for the Authorization header, which could
47  * happen for `Credentials` that need to be periodically refreshed, the
48  * underlying `Status` will indicate failure details from the refresh HTTP
49  * request. Otherwise, the returned value will contain the Authorization
50  * header to be used in HTTP requests.
51  */
52  virtual StatusOr<std::string> AuthorizationHeader() = 0;
53 
54  /**
55  * Try to sign @p string_to_sign using @p service_account.
56  *
57  * Some %Credentials types can locally sign a blob, most often just on behalf
58  * of an specific service account. This function returns an error if the
59  * credentials cannot sign the blob at all, or if the service account is a
60  * mismatch.
61  */
62  virtual StatusOr<std::vector<std::uint8_t>> SignBlob(
63  SigningAccount const& service_account,
64  std::string const& string_to_sign) const;
65 
66  /// Return the account's email associated with these credentials, if any.
67  virtual std::string AccountEmail() const { return std::string{}; }
68 
69  /// Return the account's key_id associated with these credentials, if any.
70  virtual std::string KeyId() const { return std::string{}; }
71 };
72 
73 } // namespace oauth2
75 } // namespace storage
76 } // namespace cloud
77 } // namespace google
78 
79 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_CREDENTIALS_H