google_api_keys.h 5.5 KB

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