google_api_keys.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GOOGLE_APIS_GOOGLE_API_KEYS_H_
  5. #define GOOGLE_APIS_GOOGLE_API_KEYS_H_
  6. // If you add more includes to this file, you also need to add them to
  7. // google_api_keys_unittest.cc.
  8. #include <string>
  9. #include "build/build_config.h"
  10. // These functions enable you to retrieve keys to use for Google APIs
  11. // such as Translate and Safe Browsing.
  12. //
  13. // You can retrieve either an "API key" (sometimes called a developer
  14. // key) which identifies you (or the company you work for) as a
  15. // developer, or you can retrieve the "client ID" and "client secret"
  16. // used by you (or the company you work for) to generate OAuth2
  17. // requests.
  18. //
  19. // Each developer (or group of developers working together for a
  20. // single company) must request a Google API key and the client ID and
  21. // client secret for OAuth2. See
  22. // https://developers.google.com/console/help/ and
  23. // https://developers.google.com/console/.
  24. //
  25. // The keys must either be provided using preprocessor variables (set via e.g.
  26. // GN args). Alternatively, they can be overridden at runtime using one of the
  27. // following methods (in priority order):
  28. // - Command line parameters (only for GOOGLE_CLIENT_ID_MAIN and
  29. // GOOGLE_CLIENT_SECRET_MAIN values). The command-line parameters are
  30. // --oauth2-client-id and --oauth2-client-secret.
  31. // - Config file entry of the same name. Path to a config file is set via the
  32. // --gaia-config command line parameter. See google_apis/gaia/gaia_config.h
  33. // for syntax reference.
  34. // - Environment variables of the same name. Environment variable overrides will
  35. // be ignored for official Google Chrome builds.
  36. //
  37. // The names of the preprocessor variables (or environment variables
  38. // to override them at runtime in Chromium builds) are as follows:
  39. // - GOOGLE_API_KEY: The API key, a.k.a. developer key.
  40. // - GOOGLE_DEFAULT_CLIENT_ID: If set, this is used as the default for
  41. // all client IDs not otherwise set. This is intended only for
  42. // development.
  43. // - GOOGLE_DEFAULT_CLIENT_SECRET: If set, this is used as the default
  44. // for all client secrets. This is intended only for development.
  45. // - GOOGLE_CLIENT_ID_[client name]
  46. // - GOOGLE_CLIENT_SECRET_[client name]
  47. // (e.g. GOOGLE_CLIENT_SECRET_REMOTING, i.e. one for each item in
  48. // the OAuth2Client enumeration below)
  49. //
  50. // If some of the parameters mentioned above are not provided,
  51. // Chromium will still build and run, but services that require them
  52. // may fail to work without warning. They should do so gracefully,
  53. // similar to what would happen when a network connection is
  54. // unavailable.
  55. namespace google_apis {
  56. extern const char kAPIKeysDevelopersHowToURL[];
  57. // Returns true if no dummy API key is set.
  58. bool HasAPIKeyConfigured();
  59. // Retrieves the API key, a.k.a. developer key, or a dummy string
  60. // if not set.
  61. //
  62. // Note that the key should be escaped for the context you use it in,
  63. // e.g. URL-escaped if you use it in a URL.
  64. std::string GetAPIKey();
  65. // Non-stable channels may have a different Google API key.
  66. std::string GetNonStableAPIKey();
  67. // Retrieves the Chrome Remote Desktop API key.
  68. std::string GetRemotingAPIKey();
  69. // Retrieves the Sharing API Key.
  70. std::string GetSharingAPIKey();
  71. // Retrieves the Speech On-Device API (SODA) API Key.
  72. std::string GetSodaAPIKey();
  73. // Retrieves the ReadAloud API Key.
  74. std::string GetReadAloudAPIKey();
  75. // Retrieves the Fresnel API Key.
  76. std::string GetFresnelAPIKey();
  77. #if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_FUCHSIA)
  78. // Sets the API key. This should be called as early as possible before this
  79. // API key is even accessed. It must be called before GetAPIKey.
  80. // TODO(https://crbug.com/1166007): Enforce this is called before GetAPIKey.
  81. void SetAPIKey(const std::string& api_key);
  82. #endif
  83. // Retrieves the key used to sign metrics (UMA/UKM) uploads.
  84. std::string GetMetricsKey();
  85. // Represents the different sets of client IDs and secrets in use.
  86. enum OAuth2Client {
  87. CLIENT_MAIN, // Several different features use this.
  88. CLIENT_REMOTING,
  89. CLIENT_REMOTING_HOST,
  90. CLIENT_NUM_ITEMS // Must be last item.
  91. };
  92. // Returns true if no dummy OAuth2 client ID and secret are set.
  93. bool HasOAuthClientConfigured();
  94. // Retrieves the OAuth2 client ID for the specified client, or the
  95. // empty string if not set.
  96. //
  97. // Note that the ID should be escaped for the context you use it in,
  98. // e.g. URL-escaped if you use it in a URL.
  99. std::string GetOAuth2ClientID(OAuth2Client client);
  100. // Retrieves the OAuth2 client secret for the specified client, or the
  101. // empty string if not set.
  102. //
  103. // Note that the secret should be escaped for the context you use it
  104. // in, e.g. URL-escaped if you use it in a URL.
  105. std::string GetOAuth2ClientSecret(OAuth2Client client);
  106. #if BUILDFLAG(IS_IOS)
  107. // Sets the client id for the specified client. Should be called as early as
  108. // possible before these ids are accessed.
  109. void SetOAuth2ClientID(OAuth2Client client, const std::string& client_id);
  110. // Sets the client secret for the specified client. Should be called as early as
  111. // possible before these secrets are accessed.
  112. void SetOAuth2ClientSecret(OAuth2Client client,
  113. const std::string& client_secret);
  114. #endif
  115. // Returns the auth token for the data reduction proxy.
  116. std::string GetSpdyProxyAuthValue();
  117. // Returns if the API key using in the current build is the one for official
  118. // Google Chrome.
  119. bool IsGoogleChromeAPIKeyUsed();
  120. } // namespace google_apis
  121. #endif // GOOGLE_APIS_GOOGLE_API_KEYS_H_