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