[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 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 | |
[email protected] | 6386cf5 | 2012-09-07 04:26:37 | [diff] [blame] | 5 | #ifndef GOOGLE_APIS_GOOGLE_API_KEYS_H_ |
| 6 | #define GOOGLE_APIS_GOOGLE_API_KEYS_H_ |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 7 | |
[email protected] | e03604b | 2013-01-10 23:38:22 | [diff] [blame] | 8 | // If you add more includes to this file, you also need to add them to |
| 9 | // google_api_keys_unittest.cc. |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 10 | #include <string> |
| 11 | |
Sharon Yang | 41d26ed | 2021-01-14 21:23:52 | [diff] [blame^] | 12 | #include "build/build_config.h" |
| 13 | |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 14 | // These functions enable you to retrieve keys to use for Google APIs |
| 15 | // such as Translate and Safe Browsing. |
| 16 | // |
| 17 | // You can retrieve either an "API key" (sometimes called a developer |
| 18 | // key) which identifies you (or the company you work for) as a |
| 19 | // developer, or you can retrieve the "client ID" and "client secret" |
| 20 | // used by you (or the company you work for) to generate OAuth2 |
| 21 | // requests. |
| 22 | // |
| 23 | // Each developer (or group of developers working together for a |
| 24 | // single company) must request a Google API key and the client ID and |
| 25 | // client secret for OAuth2. See |
| 26 | // https://developers.google.com/console/help/ and |
| 27 | // https://developers.google.com/console/. |
| 28 | // |
Alex Ilin | 9ac2a9c | 2020-07-06 14:28:55 | [diff] [blame] | 29 | // The keys must either be provided using preprocessor variables (set via e.g. |
| 30 | // GN args). Alternatively, they can be overridden at runtime using one of the |
| 31 | // following methods (in priority order): |
| 32 | // - Command line parameters (only for GOOGLE_CLIENT_ID_MAIN and |
| 33 | // GOOGLE_CLIENT_SECRET_MAIN values). The command-line parameters are |
| 34 | // --oauth2-client-id and --oauth2-client-secret. |
| 35 | // - Config file entry of the same name. Path to a config file is set via the |
| 36 | // --gaia-config command line parameter. See google_apis/gaia/gaia_config.h |
| 37 | // for syntax reference. |
| 38 | // - Environment variables of the same name. Environment variable overrides will |
| 39 | // be ignored for official Google Chrome builds. |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 40 | // |
| 41 | // The names of the preprocessor variables (or environment variables |
robertshield | 8d06e9e | 2017-06-23 14:09:18 | [diff] [blame] | 42 | // to override them at runtime in Chromium builds) are as follows: |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 43 | // - GOOGLE_API_KEY: The API key, a.k.a. developer key. |
| 44 | // - GOOGLE_DEFAULT_CLIENT_ID: If set, this is used as the default for |
| 45 | // all client IDs not otherwise set. This is intended only for |
| 46 | // development. |
| 47 | // - GOOGLE_DEFAULT_CLIENT_SECRET: If set, this is used as the default |
| 48 | // for all client secrets. This is intended only for development. |
| 49 | // - GOOGLE_CLIENT_ID_[client name] |
| 50 | // (e.g. GOOGLE_CLIENT_ID_CLOUD_PRINT, i.e. one for each item in the |
| 51 | // OAuth2Client enumeration below) |
| 52 | // - GOOGLE_CLIENT_SECRET_[client name] |
| 53 | // (e.g. GOOGLE_CLIENT_SECRET_CLOUD_PRINT, i.e. one for each item in |
| 54 | // the OAuth2Client enumeration below) |
| 55 | // |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 56 | // If some of the parameters mentioned above are not provided, |
| 57 | // Chromium will still build and run, but services that require them |
| 58 | // may fail to work without warning. They should do so gracefully, |
| 59 | // similar to what would happen when a network connection is |
| 60 | // unavailable. |
| 61 | |
| 62 | namespace google_apis { |
| 63 | |
dzhioev | bd066141 | 2015-10-20 23:00:07 | [diff] [blame] | 64 | extern const char kAPIKeysDevelopersHowToURL[]; |
| 65 | |
Mihai Sardarescu | 806c3540 | 2018-06-20 17:01:06 | [diff] [blame] | 66 | // Returns true if no dummy API key is set. |
| 67 | bool HasAPIKeyConfigured(); |
[email protected] | e7dd789 | 2013-05-16 19:10:40 | [diff] [blame] | 68 | |
| 69 | // Retrieves the API key, a.k.a. developer key, or a dummy string |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 70 | // if not set. |
| 71 | // |
| 72 | // Note that the key should be escaped for the context you use it in, |
| 73 | // e.g. URL-escaped if you use it in a URL. |
| 74 | std::string GetAPIKey(); |
| 75 | |
jkrcal | f7baf81 | 2016-03-22 10:23:42 | [diff] [blame] | 76 | // Non-stable channels may have a different Google API key. |
| 77 | std::string GetNonStableAPIKey(); |
| 78 | |
Yuwei Huang | 701d2093 | 2019-05-10 22:19:02 | [diff] [blame] | 79 | // Retrieves the Chrome Remote Desktop API key. |
| 80 | std::string GetRemotingAPIKey(); |
Yuwei Huang | 48b145e7 | 2019-02-13 19:07:26 | [diff] [blame] | 81 | |
Himanshu Jaju | 6d02188 | 2020-01-23 10:32:48 | [diff] [blame] | 82 | // Retrieves the Sharing API Key. |
| 83 | std::string GetSharingAPIKey(); |
| 84 | |
evliu | dcab713 | 2020-07-23 09:17:21 | [diff] [blame] | 85 | // Retrieves the Speech On-Device API (SODA) API Key. |
| 86 | std::string GetSodaAPIKey(); |
| 87 | |
Sharon Yang | 41d26ed | 2021-01-14 21:23:52 | [diff] [blame^] | 88 | #if defined(OS_IOS) || defined(OS_FUCHSIA) |
jzw | 2d292082 | 2017-04-20 09:19:29 | [diff] [blame] | 89 | // Sets the API key. This should be called as early as possible before this |
Sharon Yang | 41d26ed | 2021-01-14 21:23:52 | [diff] [blame^] | 90 | // API key is even accessed. It must be called before GetAPIKey. |
| 91 | // TODO(https://crbug.com/1166007): Enforce this is called before GetAPIKey. |
jzw | 2d292082 | 2017-04-20 09:19:29 | [diff] [blame] | 92 | void SetAPIKey(const std::string& api_key); |
| 93 | #endif |
| 94 | |
Jesse Doherty | bc473b4 | 2019-02-14 16:05:34 | [diff] [blame] | 95 | // Retrieves the key used to sign metrics (UMA/UKM) uploads. |
| 96 | std::string GetMetricsKey(); |
| 97 | |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 98 | // Represents the different sets of client IDs and secrets in use. |
| 99 | enum OAuth2Client { |
| 100 | CLIENT_MAIN, // Several different features use this. |
| 101 | CLIENT_CLOUD_PRINT, |
| 102 | CLIENT_REMOTING, |
[email protected] | d66d8174 | 2013-08-16 05:18:38 | [diff] [blame] | 103 | CLIENT_REMOTING_HOST, |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 104 | |
| 105 | CLIENT_NUM_ITEMS // Must be last item. |
| 106 | }; |
| 107 | |
Mihai Sardarescu | 806c3540 | 2018-06-20 17:01:06 | [diff] [blame] | 108 | // Returns true if no dummy OAuth2 client ID and secret are set. |
| 109 | bool HasOAuthClientConfigured(); |
| 110 | |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 111 | // Retrieves the OAuth2 client ID for the specified client, or the |
| 112 | // empty string if not set. |
| 113 | // |
| 114 | // Note that the ID should be escaped for the context you use it in, |
| 115 | // e.g. URL-escaped if you use it in a URL. |
| 116 | std::string GetOAuth2ClientID(OAuth2Client client); |
| 117 | |
| 118 | // Retrieves the OAuth2 client secret for the specified client, or the |
| 119 | // empty string if not set. |
| 120 | // |
| 121 | // Note that the secret should be escaped for the context you use it |
| 122 | // in, e.g. URL-escaped if you use it in a URL. |
| 123 | std::string GetOAuth2ClientSecret(OAuth2Client client); |
| 124 | |
jzw | 2d292082 | 2017-04-20 09:19:29 | [diff] [blame] | 125 | #if defined(OS_IOS) |
| 126 | // Sets the client id for the specified client. Should be called as early as |
| 127 | // possible before these ids are accessed. |
| 128 | void SetOAuth2ClientID(OAuth2Client client, const std::string& client_id); |
| 129 | |
| 130 | // Sets the client secret for the specified client. Should be called as early as |
| 131 | // possible before these secrets are accessed. |
| 132 | void SetOAuth2ClientSecret(OAuth2Client client, |
| 133 | const std::string& client_secret); |
| 134 | #endif |
kundaji | 033fb6ec | 2014-10-15 19:11:08 | [diff] [blame] | 135 | // Returns the auth token for the data reduction proxy. |
| 136 | std::string GetSpdyProxyAuthValue(); |
| 137 | |
[email protected] | e4b54e3 | 2014-01-17 13:55:20 | [diff] [blame] | 138 | // Returns if the API key using in the current build is the one for official |
| 139 | // Google Chrome. |
| 140 | bool IsGoogleChromeAPIKeyUsed(); |
| 141 | |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 142 | } // namespace google_apis |
| 143 | |
[email protected] | 6386cf5 | 2012-09-07 04:26:37 | [diff] [blame] | 144 | #endif // GOOGLE_APIS_GOOGLE_API_KEYS_H_ |