diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index a63f96bfc91..4b67ef8fdad 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -267,10 +267,7 @@ void grpc_oauth2_token_fetcher_credentials::on_http_response( // Invoke callbacks for all pending requests. while (pending_request != nullptr) { if (status == GRPC_CREDENTIALS_OK) { - pending_request->md->Append( - GRPC_AUTHORIZATION_METADATA_KEY, access_token_value->Ref(), - [](absl::string_view, const grpc_core::Slice&) { abort(); }); - pending_request->result = std::move(pending_request->md); + pending_request->result = access_token_value->Ref(); } else { auto err = GRPC_ERROR_CREATE_REFERENCING( "Error occurred when fetching oauth2 token.", &error, 1); @@ -338,7 +335,15 @@ grpc_oauth2_token_fetcher_credentials::GetRequestMetadata( if (!pending_request->done.load(std::memory_order_acquire)) { return grpc_core::Pending{}; } - return std::move(pending_request->result); + if (pending_request->result.ok()) { + pending_request->md->Append( + GRPC_AUTHORIZATION_METADATA_KEY, + std::move(*pending_request->result), + [](absl::string_view, const grpc_core::Slice&) { abort(); }); + return std::move(pending_request->md); + } else { + return pending_request->result.status(); + } }; } diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h index 4a18c28aae2..9815a8d3ee3 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h @@ -102,7 +102,7 @@ struct grpc_oauth2_pending_get_request_metadata grpc_polling_entity* pollent; grpc_core::ClientMetadataHandle md; struct grpc_oauth2_pending_get_request_metadata* next; - absl::StatusOr result; + absl::StatusOr result; }; // -- Oauth2 Token Fetcher credentials --