external_account_credentials.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_EXTERNAL_EXTERNAL_ACCOUNT_CREDENTIALS_H
18 #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_EXTERNAL_EXTERNAL_ACCOUNT_CREDENTIALS_H
19 
21 
22 #include <functional>
23 #include <string>
24 #include <vector>
25 
26 #include "absl/strings/string_view.h"
27 
36 #include "src/core/lib/json/json.h"
38 
39 namespace grpc_core {
40 
41 // Base external account credentials. The base class implements common logic for
42 // exchanging external account credentials for GCP access token to authorize
43 // requests to GCP APIs. The specific logic of retrieving subject token is
44 // implemented in subclasses.
47  public:
48  // External account credentials json interface.
49  struct Options {
61  };
62 
64  const Json& json, std::vector<std::string> scopes,
66 
67  ExternalAccountCredentials(Options options, std::vector<std::string> scopes);
68  ~ExternalAccountCredentials() override;
69  std::string debug_string() override;
70 
71  protected:
72  // This is a helper struct to pass information between multiple callback based
73  // asynchronous calls.
78 
79  // Contextual parameters passed from
80  // grpc_oauth2_token_fetcher_credentials::fetch_oauth2().
83 
84  // Reusable token fetch http response and closure.
87  };
88 
89  // Subclasses of base external account credentials need to override this
90  // method to implement the specific subject token retrieval logic.
91  // Once the subject token is ready, subclasses need to invoke
92  // the callback function (cb) to pass the subject token (or error)
93  // back.
94  virtual void RetrieveSubjectToken(
97 
98  private:
99  // This method implements the common token fetch logic and it will be called
100  // when grpc_oauth2_token_fetcher_credentials request a new access token.
103  Timestamp deadline) override;
104 
107 
108  void ExchangeToken(absl::string_view subject_token);
109  static void OnExchangeToken(void* arg, grpc_error_handle error);
111 
115 
117 
119  std::vector<std::string> scopes_;
120 
125 };
126 
127 } // namespace grpc_core
128 
129 #endif // GRPC_CORE_LIB_SECURITY_CREDENTIALS_EXTERNAL_EXTERNAL_ACCOUNT_CREDENTIALS_H
orphanable.h
ctx
Definition: benchmark-async.c:30
grpc_core::ExternalAccountCredentials::~ExternalAccountCredentials
~ExternalAccountCredentials() override
Definition: external_account_credentials.cc:237
grpc_core::ExternalAccountCredentials::OnImpersenateServiceAccount
static void OnImpersenateServiceAccount(void *arg, grpc_error_handle error)
Definition: external_account_credentials.cc:457
polling_entity.h
grpc_core::ExternalAccountCredentials::OnExchangeToken
static void OnExchangeToken(void *arg, grpc_error_handle error)
Definition: external_account_credentials.cc:363
grpc_core::ExternalAccountCredentials::response_cb_
grpc_iomgr_cb_func response_cb_
Definition: external_account_credentials.h:124
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::ExternalAccountCredentials::HTTPRequestContext::pollent
grpc_polling_entity * pollent
Definition: external_account_credentials.h:81
options
double_dict options[]
Definition: capstone_test.c:55
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_core::Timestamp
Definition: src/core/lib/gprpp/time.h:62
grpc_core::ExternalAccountCredentials::Options::client_id
std::string client_id
Definition: external_account_credentials.h:58
grpc_core::ExternalAccountCredentials::HTTPRequestContext
Definition: external_account_credentials.h:74
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::ExternalAccountCredentials
Definition: external_account_credentials.h:45
closure.h
grpc_core::ExternalAccountCredentials::scopes_
std::vector< std::string > scopes_
Definition: external_account_credentials.h:119
grpc_core::ExternalAccountCredentials::RetrieveSubjectToken
virtual void RetrieveSubjectToken(HTTPRequestContext *ctx, const Options &options, std::function< void(std::string, grpc_error_handle)> cb)=0
grpc_core::ExternalAccountCredentials::HTTPRequestContext::~HTTPRequestContext
~HTTPRequestContext()
Definition: external_account_credentials.h:77
grpc_oauth2_token_fetcher_credentials
Definition: oauth2_credentials.h:112
grpc_http_response
Definition: src/core/lib/http/parser.h:85
grpc_core::ExternalAccountCredentials::ImpersenateServiceAccount
void ImpersenateServiceAccount()
Definition: external_account_credentials.cc:395
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
Json
JSON (JavaScript Object Notation).
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:227
req
static uv_connect_t req
Definition: test-connection-fail.c:30
httpcli.h
grpc_core::ExternalAccountCredentials::ExternalAccountCredentials
ExternalAccountCredentials(Options options, std::vector< std::string > scopes)
Definition: external_account_credentials.cc:228
arg
Definition: cmdline.cc:40
time.h
grpc_core::ExternalAccountCredentials::HTTPRequestContext::HTTPRequestContext
HTTPRequestContext(grpc_polling_entity *pollent, Timestamp deadline)
Definition: external_account_credentials.h:75
grpc_core::ExternalAccountCredentials::HTTPRequestContext::closure
grpc_closure closure
Definition: external_account_credentials.h:85
grpc_http_response_destroy
void grpc_http_response_destroy(grpc_http_response *response)
Definition: src/core/lib/http/parser.cc:434
error.h
grpc_core::ExternalAccountCredentials::FinishTokenFetch
void FinishTokenFetch(grpc_error_handle error)
Definition: external_account_credentials.cc:520
grpc_polling_entity
Definition: polling_entity.h:38
json.h
grpc_core::ExternalAccountCredentials::HTTPRequestContext::deadline
Timestamp deadline
Definition: external_account_credentials.h:82
grpc_core::ExternalAccountCredentials::ctx_
HTTPRequestContext * ctx_
Definition: external_account_credentials.h:122
grpc_credentials_metadata_request
Definition: oauth2_credentials.h:85
grpc_core::ExternalAccountCredentials::Options::token_url
std::string token_url
Definition: external_account_credentials.h:54
grpc_core::ExternalAccountCredentials::Options::service_account_impersonation_url
std::string service_account_impersonation_url
Definition: external_account_credentials.h:53
grpc_core::ExternalAccountCredentials::fetch_oauth2
void fetch_oauth2(grpc_credentials_metadata_request *req, grpc_polling_entity *pollent, grpc_iomgr_cb_func cb, Timestamp deadline) override
Definition: external_account_credentials.cc:257
grpc_core::ExternalAccountCredentials::Options::audience
std::string audience
Definition: external_account_credentials.h:51
grpc_core::ExternalAccountCredentials::HTTPRequestContext::response
grpc_http_response response
Definition: external_account_credentials.h:86
grpc_core::ExternalAccountCredentials::OnRetrieveSubjectTokenInternal
void OnRetrieveSubjectTokenInternal(absl::string_view subject_token, grpc_error_handle error)
Definition: external_account_credentials.cc:271
grpc_core::ExternalAccountCredentials::debug_string
std::string debug_string() override
Definition: external_account_credentials.cc:239
parser.h
grpc_core::ExternalAccountCredentials::http_request_
OrphanablePtr< HttpRequest > http_request_
Definition: external_account_credentials.h:121
grpc_core::ExternalAccountCredentials::Options::quota_project_id
std::string quota_project_id
Definition: external_account_credentials.h:57
grpc_core::ExternalAccountCredentials::Options::credential_source
Json credential_source
Definition: external_account_credentials.h:56
grpc_core::OrphanablePtr
std::unique_ptr< T, Deleter > OrphanablePtr
Definition: orphanable.h:64
grpc_iomgr_cb_func
void(* grpc_iomgr_cb_func)(void *arg, grpc_error_handle error)
Definition: closure.h:53
grpc_core::ExternalAccountCredentials::options_
Options options_
Definition: external_account_credentials.h:118
ref_counted_ptr.h
grpc_core::ExternalAccountCredentials::metadata_req_
grpc_credentials_metadata_request * metadata_req_
Definition: external_account_credentials.h:123
grpc_error
Definition: error_internal.h:42
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
oauth2_credentials.h
grpc_core::ExternalAccountCredentials::OnImpersenateServiceAccountInternal
void OnImpersenateServiceAccountInternal(grpc_error_handle error)
Definition: external_account_credentials.cc:464
grpc_core::ExternalAccountCredentials::Options::workforce_pool_user_project
std::string workforce_pool_user_project
Definition: external_account_credentials.h:60
grpc_closure
Definition: closure.h:56
grpc_core::ExternalAccountCredentials::ExchangeToken
void ExchangeToken(absl::string_view subject_token)
Definition: external_account_credentials.cc:280
grpc_core::ExternalAccountCredentials::Create
static RefCountedPtr< ExternalAccountCredentials > Create(const Json &json, std::vector< std::string > scopes, grpc_error_handle *error)
Definition: external_account_credentials.cc:102
grpc_core::ExternalAccountCredentials::Options::type
std::string type
Definition: external_account_credentials.h:50
cb
OPENSSL_EXPORT pem_password_cb * cb
Definition: pem.h:351
grpc_core::ExternalAccountCredentials::Options::token_info_url
std::string token_info_url
Definition: external_account_credentials.h:55
grpc_core::ExternalAccountCredentials::Options::subject_token_type
std::string subject_token_type
Definition: external_account_credentials.h:52
grpc_core::ExternalAccountCredentials::Options
Definition: external_account_credentials.h:49
grpc_core::ExternalAccountCredentials::Options::client_secret
std::string client_secret
Definition: external_account_credentials.h:59
grpc_core::ExternalAccountCredentials::OnExchangeTokenInternal
void OnExchangeTokenInternal(grpc_error_handle error)
Definition: external_account_credentials.cc:370
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:21