HttpPost::HttpPost(net::URLRequestContextGetter* url_context_getter,
const std::string& server_host,
const std::string& rpc_name,
- const std::string& tracing_token,
std::string api_key,
+ const std::string& auth_token,
+ const std::string& tracing_token,
const google::protobuf::MessageLite& request_proto) {
// Create the base URL to call.
GURL url(server_host + "/" + rpc_name);
url, kTracingField, "token:" + tracing_token);
}
+ // If we have no auth token, authenticate using the API key.
// If no API key is specified, use the Chrome API key.
- if (api_key.empty()) {
+ if (auth_token.empty()) {
+ if (api_key.empty()) {
#ifdef GOOGLE_CHROME_BUILD
- DCHECK(google_apis::HasKeysConfigured());
- api_key = google_apis::GetAPIKey();
+ DCHECK(google_apis::HasKeysConfigured());
+ api_key = google_apis::GetAPIKey();
#else
- LOG(ERROR) << "No Copresence API key provided";
+ LOG(ERROR) << "No Copresence API key provided";
#endif
+ }
+ url = net::AppendQueryParameter(url, kApiKeyField, api_key);
}
- url = net::AppendQueryParameter(url, kApiKeyField, api_key);
// Serialize the proto for transmission.
std::string request_data;
net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SEND_AUTH_DATA);
url_fetcher_->SetUploadData("application/x-protobuf", request_data);
+ if (!auth_token.empty()) {
+ url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + auth_token);
+ }
}
HttpPost::~HttpPost() {}