[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 | |
| 12 | // These functions enable you to retrieve keys to use for Google APIs |
| 13 | // such as Translate and Safe Browsing. |
| 14 | // |
| 15 | // You can retrieve either an "API key" (sometimes called a developer |
| 16 | // key) which identifies you (or the company you work for) as a |
| 17 | // developer, or you can retrieve the "client ID" and "client secret" |
| 18 | // used by you (or the company you work for) to generate OAuth2 |
| 19 | // requests. |
| 20 | // |
| 21 | // Each developer (or group of developers working together for a |
| 22 | // single company) must request a Google API key and the client ID and |
| 23 | // client secret for OAuth2. See |
| 24 | // https://developers.google.com/console/help/ and |
| 25 | // https://developers.google.com/console/. |
| 26 | // |
| 27 | // The keys must either be provided using preprocessor variables (set |
| 28 | // via e.g. ~/.gyp/include.gypi). Alternatively, they can be |
| 29 | // overridden at runtime using environment variables of the same name. |
| 30 | // |
| 31 | // The names of the preprocessor variables (or environment variables |
| 32 | // to override them at runtime) are as follows: |
| 33 | // - GOOGLE_API_KEY: The API key, a.k.a. developer key. |
| 34 | // - GOOGLE_DEFAULT_CLIENT_ID: If set, this is used as the default for |
| 35 | // all client IDs not otherwise set. This is intended only for |
| 36 | // development. |
| 37 | // - GOOGLE_DEFAULT_CLIENT_SECRET: If set, this is used as the default |
| 38 | // for all client secrets. This is intended only for development. |
| 39 | // - GOOGLE_CLIENT_ID_[client name] |
| 40 | // (e.g. GOOGLE_CLIENT_ID_CLOUD_PRINT, i.e. one for each item in the |
| 41 | // OAuth2Client enumeration below) |
| 42 | // - GOOGLE_CLIENT_SECRET_[client name] |
| 43 | // (e.g. GOOGLE_CLIENT_SECRET_CLOUD_PRINT, i.e. one for each item in |
| 44 | // the OAuth2Client enumeration below) |
| 45 | // |
| 46 | // The GOOGLE_CLIENT_ID_MAIN and GOOGLE_CLIENT_SECRET_MAIN values can |
| 47 | // also be set via the command line (this overrides any other |
| 48 | // setting). The command-line parameters are --oauth2-client-id and |
| 49 | // --oauth2-client-secret. |
| 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 | |
| 57 | namespace google_apis { |
| 58 | |
dzhioev | bd066141 | 2015-10-20 23:00:07 | [diff] [blame] | 59 | extern const char kAPIKeysDevelopersHowToURL[]; |
| 60 | |
[email protected] | e7dd789 | 2013-05-16 19:10:40 | [diff] [blame] | 61 | // Returns true if no dummy API keys or OAuth2 tokens are set. |
| 62 | bool HasKeysConfigured(); |
| 63 | |
| 64 | // Retrieves the API key, a.k.a. developer key, or a dummy string |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 65 | // if not set. |
| 66 | // |
| 67 | // Note that the key should be escaped for the context you use it in, |
| 68 | // e.g. URL-escaped if you use it in a URL. |
| 69 | std::string GetAPIKey(); |
| 70 | |
jkrcal | f7baf81 | 2016-03-22 10:23:42 | [diff] [blame] | 71 | // Non-stable channels may have a different Google API key. |
| 72 | std::string GetNonStableAPIKey(); |
| 73 | |
sergeyu | cb475fa | 2016-02-23 19:47:06 | [diff] [blame] | 74 | std::string GetRemotingAPIKey(); |
| 75 | |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 76 | // Represents the different sets of client IDs and secrets in use. |
| 77 | enum OAuth2Client { |
| 78 | CLIENT_MAIN, // Several different features use this. |
| 79 | CLIENT_CLOUD_PRINT, |
| 80 | CLIENT_REMOTING, |
[email protected] | d66d8174 | 2013-08-16 05:18:38 | [diff] [blame] | 81 | CLIENT_REMOTING_HOST, |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 82 | |
| 83 | CLIENT_NUM_ITEMS // Must be last item. |
| 84 | }; |
| 85 | |
| 86 | // Retrieves the OAuth2 client ID for the specified client, or the |
| 87 | // empty string if not set. |
| 88 | // |
| 89 | // Note that the ID should be escaped for the context you use it in, |
| 90 | // e.g. URL-escaped if you use it in a URL. |
| 91 | std::string GetOAuth2ClientID(OAuth2Client client); |
| 92 | |
| 93 | // Retrieves the OAuth2 client secret for the specified client, or the |
| 94 | // empty string if not set. |
| 95 | // |
| 96 | // Note that the secret should be escaped for the context you use it |
| 97 | // in, e.g. URL-escaped if you use it in a URL. |
| 98 | std::string GetOAuth2ClientSecret(OAuth2Client client); |
| 99 | |
kundaji | 033fb6ec | 2014-10-15 19:11:08 | [diff] [blame] | 100 | // Returns the auth token for the data reduction proxy. |
| 101 | std::string GetSpdyProxyAuthValue(); |
| 102 | |
[email protected] | e4b54e3 | 2014-01-17 13:55:20 | [diff] [blame] | 103 | // Returns if the API key using in the current build is the one for official |
| 104 | // Google Chrome. |
| 105 | bool IsGoogleChromeAPIKeyUsed(); |
| 106 | |
[email protected] | e5e894ff | 2012-09-06 02:18:47 | [diff] [blame] | 107 | } // namespace google_apis |
| 108 | |
[email protected] | 6386cf5 | 2012-09-07 04:26:37 | [diff] [blame] | 109 | #endif // GOOGLE_APIS_GOOGLE_API_KEYS_H_ |