0

Plumb API key for Fresnel service authorization.

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}
This commit is contained in:
Hirthanan Subenderan
2021-12-02 19:22:17 +00:00
committed by Chromium LUCI CQ
parent 0f3ae90e19
commit 658abca48e
2 changed files with 18 additions and 0 deletions

@ -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
@ -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,
@ -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_; }
@ -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];
@ -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);

@ -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.