aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/security/credentials/oauth2
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/security/credentials/oauth2')
-rw-r--r--src/core/lib/security/credentials/oauth2/oauth2_credentials.cc102
-rw-r--r--src/core/lib/security/credentials/oauth2/oauth2_credentials.h7
2 files changed, 50 insertions, 59 deletions
diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
index ccefb4db9c..e243ea52c6 100644
--- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
+++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
@@ -103,21 +103,19 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) {
// Oauth2 Token Fetcher credentials.
//
-static void oauth2_token_fetcher_destruct(grpc_exec_ctx* exec_ctx,
- grpc_call_credentials* creds) {
+static void oauth2_token_fetcher_destruct(grpc_call_credentials* creds) {
grpc_oauth2_token_fetcher_credentials* c =
(grpc_oauth2_token_fetcher_credentials*)creds;
- GRPC_MDELEM_UNREF(exec_ctx, c->access_token_md);
+ GRPC_MDELEM_UNREF(c->access_token_md);
gpr_mu_destroy(&c->mu);
- grpc_pollset_set_destroy(exec_ctx,
- grpc_polling_entity_pollset_set(&c->pollent));
- grpc_httpcli_context_destroy(exec_ctx, &c->httpcli_context);
+ grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&c->pollent));
+ grpc_httpcli_context_destroy(&c->httpcli_context);
}
grpc_credentials_status
grpc_oauth2_token_fetcher_credentials_parse_server_response(
- grpc_exec_ctx* exec_ctx, const grpc_http_response* response,
- grpc_mdelem* token_md, grpc_millis* token_lifetime) {
+ const grpc_http_response* response, grpc_mdelem* token_md,
+ grpc_millis* token_lifetime) {
char* null_terminated_body = nullptr;
char* new_access_token = nullptr;
grpc_credentials_status status = GRPC_CREDENTIALS_OK;
@@ -184,9 +182,8 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
gpr_asprintf(&new_access_token, "%s %s", token_type->value,
access_token->value);
*token_lifetime = strtol(expires_in->value, nullptr, 10) * GPR_MS_PER_SEC;
- if (!GRPC_MDISNULL(*token_md)) GRPC_MDELEM_UNREF(exec_ctx, *token_md);
+ if (!GRPC_MDISNULL(*token_md)) GRPC_MDELEM_UNREF(*token_md);
*token_md = grpc_mdelem_from_slices(
- exec_ctx,
grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY),
grpc_slice_from_copied_string(new_access_token));
status = GRPC_CREDENTIALS_OK;
@@ -194,7 +191,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
end:
if (status != GRPC_CREDENTIALS_OK && !GRPC_MDISNULL(*token_md)) {
- GRPC_MDELEM_UNREF(exec_ctx, *token_md);
+ GRPC_MDELEM_UNREF(*token_md);
*token_md = GRPC_MDNULL;
}
if (null_terminated_body != nullptr) gpr_free(null_terminated_body);
@@ -203,8 +200,7 @@ end:
return status;
}
-static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx,
- void* user_data,
+static void on_oauth2_token_fetcher_http_response(void* user_data,
grpc_error* error) {
GRPC_LOG_IF_ERROR("oauth_fetch", GRPC_ERROR_REF(error));
grpc_credentials_metadata_request* r =
@@ -215,13 +211,13 @@ static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx,
grpc_millis token_lifetime;
grpc_credentials_status status =
grpc_oauth2_token_fetcher_credentials_parse_server_response(
- exec_ctx, &r->response, &access_token_md, &token_lifetime);
+ &r->response, &access_token_md, &token_lifetime);
// Update cache and grab list of pending requests.
gpr_mu_lock(&c->mu);
c->token_fetch_pending = false;
c->access_token_md = GRPC_MDELEM_REF(access_token_md);
c->token_expiration = status == GRPC_CREDENTIALS_OK
- ? grpc_exec_ctx_now(exec_ctx) + token_lifetime
+ ? grpc_core::ExecCtx::Get()->Now() + token_lifetime
: 0;
grpc_oauth2_pending_get_request_metadata* pending_request =
c->pending_requests;
@@ -236,24 +232,22 @@ static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx,
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
"Error occured when fetching oauth2 token.", &error, 1);
}
- GRPC_CLOSURE_SCHED(exec_ctx, pending_request->on_request_metadata, error);
+ GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, error);
grpc_polling_entity_del_from_pollset_set(
- exec_ctx, pending_request->pollent,
- grpc_polling_entity_pollset_set(&c->pollent));
+ pending_request->pollent, grpc_polling_entity_pollset_set(&c->pollent));
grpc_oauth2_pending_get_request_metadata* prev = pending_request;
pending_request = pending_request->next;
gpr_free(prev);
}
- GRPC_MDELEM_UNREF(exec_ctx, access_token_md);
- grpc_call_credentials_unref(exec_ctx, r->creds);
- grpc_credentials_metadata_request_destroy(exec_ctx, r);
+ GRPC_MDELEM_UNREF(access_token_md);
+ grpc_call_credentials_unref(r->creds);
+ grpc_credentials_metadata_request_destroy(r);
}
static bool oauth2_token_fetcher_get_request_metadata(
- grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds,
- grpc_polling_entity* pollent, grpc_auth_metadata_context context,
- grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
- grpc_error** error) {
+ grpc_call_credentials* creds, grpc_polling_entity* pollent,
+ grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array,
+ grpc_closure* on_request_metadata, grpc_error** error) {
grpc_oauth2_token_fetcher_credentials* c =
(grpc_oauth2_token_fetcher_credentials*)creds;
// Check if we can use the cached token.
@@ -262,13 +256,14 @@ static bool oauth2_token_fetcher_get_request_metadata(
grpc_mdelem cached_access_token_md = GRPC_MDNULL;
gpr_mu_lock(&c->mu);
if (!GRPC_MDISNULL(c->access_token_md) &&
- (c->token_expiration - grpc_exec_ctx_now(exec_ctx) > refresh_threshold)) {
+ (c->token_expiration - grpc_core::ExecCtx::Get()->Now() >
+ refresh_threshold)) {
cached_access_token_md = GRPC_MDELEM_REF(c->access_token_md);
}
if (!GRPC_MDISNULL(cached_access_token_md)) {
gpr_mu_unlock(&c->mu);
grpc_credentials_mdelem_array_add(md_array, cached_access_token_md);
- GRPC_MDELEM_UNREF(exec_ctx, cached_access_token_md);
+ GRPC_MDELEM_UNREF(cached_access_token_md);
return true;
}
// Couldn't get the token from the cache.
@@ -280,7 +275,7 @@ static bool oauth2_token_fetcher_get_request_metadata(
pending_request->on_request_metadata = on_request_metadata;
pending_request->pollent = pollent;
grpc_polling_entity_add_to_pollset_set(
- exec_ctx, pollent, grpc_polling_entity_pollset_set(&c->pollent));
+ pollent, grpc_polling_entity_pollset_set(&c->pollent));
pending_request->next = c->pending_requests;
c->pending_requests = pending_request;
bool start_fetch = false;
@@ -291,17 +286,17 @@ static bool oauth2_token_fetcher_get_request_metadata(
gpr_mu_unlock(&c->mu);
if (start_fetch) {
grpc_call_credentials_ref(creds);
- c->fetch_func(exec_ctx, grpc_credentials_metadata_request_create(creds),
+ c->fetch_func(grpc_credentials_metadata_request_create(creds),
&c->httpcli_context, &c->pollent,
on_oauth2_token_fetcher_http_response,
- grpc_exec_ctx_now(exec_ctx) + refresh_threshold);
+ grpc_core::ExecCtx::Get()->Now() + refresh_threshold);
}
return false;
}
static void oauth2_token_fetcher_cancel_get_request_metadata(
- grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds,
- grpc_credentials_mdelem_array* md_array, grpc_error* error) {
+ grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
+ grpc_error* error) {
grpc_oauth2_token_fetcher_credentials* c =
(grpc_oauth2_token_fetcher_credentials*)creds;
gpr_mu_lock(&c->mu);
@@ -317,7 +312,7 @@ static void oauth2_token_fetcher_cancel_get_request_metadata(
c->pending_requests = pending_request->next;
}
// Invoke the callback immediately with an error.
- GRPC_CLOSURE_SCHED(exec_ctx, pending_request->on_request_metadata,
+ GRPC_CLOSURE_SCHED(pending_request->on_request_metadata,
GRPC_ERROR_REF(error));
gpr_free(pending_request);
break;
@@ -351,7 +346,7 @@ static grpc_call_credentials_vtable compute_engine_vtable = {
oauth2_token_fetcher_cancel_get_request_metadata};
static void compute_engine_fetch_oauth2(
- grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* metadata_req,
+ grpc_credentials_metadata_request* metadata_req,
grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent,
grpc_iomgr_cb_func response_cb, grpc_millis deadline) {
grpc_http_header header = {(char*)"Metadata-Flavor", (char*)"Google"};
@@ -367,10 +362,10 @@ static void compute_engine_fetch_oauth2(
grpc_resource_quota* resource_quota =
grpc_resource_quota_create("oauth2_credentials");
grpc_httpcli_get(
- exec_ctx, httpcli_context, pollent, resource_quota, &request, deadline,
+ httpcli_context, pollent, resource_quota, &request, deadline,
GRPC_CLOSURE_CREATE(response_cb, metadata_req, grpc_schedule_on_exec_ctx),
&metadata_req->response);
- grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
+ grpc_resource_quota_unref_internal(resource_quota);
}
grpc_call_credentials* grpc_google_compute_engine_credentials_create(
@@ -390,12 +385,11 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create(
// Google Refresh Token credentials.
//
-static void refresh_token_destruct(grpc_exec_ctx* exec_ctx,
- grpc_call_credentials* creds) {
+static void refresh_token_destruct(grpc_call_credentials* creds) {
grpc_google_refresh_token_credentials* c =
(grpc_google_refresh_token_credentials*)creds;
grpc_auth_refresh_token_destruct(&c->refresh_token);
- oauth2_token_fetcher_destruct(exec_ctx, &c->base.base);
+ oauth2_token_fetcher_destruct(&c->base.base);
}
static grpc_call_credentials_vtable refresh_token_vtable = {
@@ -403,7 +397,7 @@ static grpc_call_credentials_vtable refresh_token_vtable = {
oauth2_token_fetcher_cancel_get_request_metadata};
static void refresh_token_fetch_oauth2(
- grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* metadata_req,
+ grpc_credentials_metadata_request* metadata_req,
grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent,
grpc_iomgr_cb_func response_cb, grpc_millis deadline) {
grpc_google_refresh_token_credentials* c =
@@ -427,11 +421,11 @@ static void refresh_token_fetch_oauth2(
grpc_resource_quota* resource_quota =
grpc_resource_quota_create("oauth2_credentials_refresh");
grpc_httpcli_post(
- exec_ctx, httpcli_context, pollent, resource_quota, &request, body,
- strlen(body), deadline,
+ httpcli_context, pollent, resource_quota, &request, body, strlen(body),
+ deadline,
GRPC_CLOSURE_CREATE(response_cb, metadata_req, grpc_schedule_on_exec_ctx),
&metadata_req->response);
- grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
+ grpc_resource_quota_unref_internal(resource_quota);
gpr_free(body);
}
@@ -483,25 +477,23 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create(
// Oauth2 Access Token credentials.
//
-static void access_token_destruct(grpc_exec_ctx* exec_ctx,
- grpc_call_credentials* creds) {
+static void access_token_destruct(grpc_call_credentials* creds) {
grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds;
- GRPC_MDELEM_UNREF(exec_ctx, c->access_token_md);
+ GRPC_MDELEM_UNREF(c->access_token_md);
}
static bool access_token_get_request_metadata(
- grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds,
- grpc_polling_entity* pollent, grpc_auth_metadata_context context,
- grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
- grpc_error** error) {
+ grpc_call_credentials* creds, grpc_polling_entity* pollent,
+ grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array,
+ grpc_closure* on_request_metadata, grpc_error** error) {
grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds;
grpc_credentials_mdelem_array_add(md_array, c->access_token_md);
return true;
}
static void access_token_cancel_get_request_metadata(
- grpc_exec_ctx* exec_ctx, grpc_call_credentials* c,
- grpc_credentials_mdelem_array* md_array, grpc_error* error) {
+ grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array,
+ grpc_error* error) {
GRPC_ERROR_UNREF(error);
}
@@ -523,11 +515,11 @@ grpc_call_credentials* grpc_access_token_credentials_create(
gpr_ref_init(&c->base.refcount, 1);
char* token_md_value;
gpr_asprintf(&token_md_value, "Bearer %s", access_token);
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
c->access_token_md = grpc_mdelem_from_slices(
- &exec_ctx, grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY),
+ grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY),
grpc_slice_from_copied_string(token_md_value));
- grpc_exec_ctx_finish(&exec_ctx);
+
gpr_free(token_md_value);
return &c->base;
}
diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h
index 32d3ff760d..0f897d9f86 100644
--- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h
+++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h
@@ -56,8 +56,7 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token);
// This object is a base for credentials that need to acquire an oauth2 token
// from an http service.
-typedef void (*grpc_fetch_oauth2_func)(grpc_exec_ctx* exec_ctx,
- grpc_credentials_metadata_request* req,
+typedef void (*grpc_fetch_oauth2_func)(grpc_credentials_metadata_request* req,
grpc_httpcli_context* http_context,
grpc_polling_entity* pollent,
grpc_iomgr_cb_func cb,
@@ -103,8 +102,8 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token(
// Exposed for testing only.
grpc_credentials_status
grpc_oauth2_token_fetcher_credentials_parse_server_response(
- grpc_exec_ctx* exec_ctx, const struct grpc_http_response* response,
- grpc_mdelem* token_md, grpc_millis* token_lifetime);
+ const struct grpc_http_response* response, grpc_mdelem* token_md,
+ grpc_millis* token_lifetime);
#ifdef __cplusplus
}