Skip to content

Commit

Permalink
Plumb API key for Fresnel service authorization.
Browse files Browse the repository at this point in the history
API key will be used for authenticating device with Fresnel Oneplatform
API. This provides one layer of protection against unauthenticated
requests.

Googlers: go/cros-device-actives-client - See Authorization section

Bug: 1204630
Change-Id: I9dc9ea0391edd1057bc666c2c66c95a196ad0dd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3069422
Commit-Queue: Hirthanan Subenderan <hirthanan@google.com>
Reviewed-by: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/main@{#947610}
  • Loading branch information
Hirthanan Subenderan authored and Chromium LUCI CQ committed Dec 2, 2021
1 parent 0f3ae90 commit 658abca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions google_apis/google_api_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
#define GOOGLE_API_KEY_READ_ALOUD DUMMY_API_TOKEN
#endif

// API key for the Fresnel API.
#if !defined(GOOGLE_API_KEY_FRESNEL)
#define GOOGLE_API_KEY_FRESNEL DUMMY_API_TOKEN
#endif

// These are used as shortcuts for developers and users providing
// OAuth credentials via preprocessor defines or environment
// variables. If set, they will be used to replace any of the client
Expand Down Expand Up @@ -154,6 +159,10 @@ class APIKeyCache {
STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_READ_ALOUD), nullptr,
std::string(), environment.get(), command_line, gaia_config);

api_key_fresnel_ = CalculateKeyValue(
GOOGLE_API_KEY_FRESNEL, STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_FRESNEL),
nullptr, std::string(), environment.get(), command_line, gaia_config);

metrics_key_ = CalculateKeyValue(
GOOGLE_METRICS_SIGNING_KEY,
STRINGIZE_NO_EXPANSION(GOOGLE_METRICS_SIGNING_KEY), nullptr,
Expand Down Expand Up @@ -221,6 +230,7 @@ class APIKeyCache {
std::string api_key_sharing() const { return api_key_sharing_; }
std::string api_key_soda() const { return api_key_soda_; }
std::string api_key_read_aloud() const { return api_key_read_aloud_; }
std::string api_key_fresnel() const { return api_key_fresnel_; }

std::string metrics_key() const { return metrics_key_; }

Expand Down Expand Up @@ -335,6 +345,7 @@ class APIKeyCache {
std::string api_key_sharing_;
std::string api_key_soda_;
std::string api_key_read_aloud_;
std::string api_key_fresnel_;
std::string metrics_key_;
std::string client_ids_[CLIENT_NUM_ITEMS];
std::string client_secrets_[CLIENT_NUM_ITEMS];
Expand Down Expand Up @@ -371,6 +382,10 @@ std::string GetReadAloudAPIKey() {
return g_api_key_cache.Get().api_key_read_aloud();
}

std::string GetFresnelAPIKey() {
return g_api_key_cache.Get().api_key_fresnel();
}

#if defined(OS_IOS) || defined(OS_FUCHSIA)
void SetAPIKey(const std::string& api_key) {
g_api_key_cache.Get().set_api_key(api_key);
Expand Down
3 changes: 3 additions & 0 deletions google_apis/google_api_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ std::string GetSodaAPIKey();
// Retrieves the ReadAloud API Key.
std::string GetReadAloudAPIKey();

// Retrieves the Fresnel API Key.
std::string GetFresnelAPIKey();

#if defined(OS_IOS) || defined(OS_FUCHSIA)
// Sets the API key. This should be called as early as possible before this
// API key is even accessed. It must be called before GetAPIKey.
Expand Down

0 comments on commit 658abca

Please sign in to comment.