Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Unified Diff: components/copresence/rpc/http_post.cc

Issue 671573003: Adding support for authenticated copresence calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing memory error Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/copresence/rpc/http_post.h ('k') | components/copresence/rpc/http_post_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/copresence/rpc/http_post.cc
diff --git a/components/copresence/rpc/http_post.cc b/components/copresence/rpc/http_post.cc
index 3f2f7a5e3eb1aaee8c6aec12a562e4e3c0550551..bde0ed336e42ab796bfe6719ad42329577e94725 100644
--- a/components/copresence/rpc/http_post.cc
+++ b/components/copresence/rpc/http_post.cc
@@ -25,8 +25,9 @@ const char HttpPost::kTracingField[] = "trace";
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);
@@ -37,16 +38,19 @@ HttpPost::HttpPost(net::URLRequestContextGetter* url_context_getter,
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;
@@ -63,6 +67,9 @@ HttpPost::HttpPost(net::URLRequestContextGetter* url_context_getter,
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() {}
« no previous file with comments | « components/copresence/rpc/http_post.h ('k') | components/copresence/rpc/http_post_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698