blob: 4275578d4e678938e13fcf068590f52d26b50e3d [file] [log] [blame]
Avi Drissman8ce0344d2022-09-13 20:40:561// Copyright 2012 The Chromium Authors
[email protected]e5e894ff2012-09-06 02:18:472// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]6386cf52012-09-07 04:26:375#ifndef GOOGLE_APIS_GOOGLE_API_KEYS_H_
6#define GOOGLE_APIS_GOOGLE_API_KEYS_H_
[email protected]e5e894ff2012-09-06 02:18:477
[email protected]e03604b2013-01-10 23:38:228// If you add more includes to this file, you also need to add them to
9// google_api_keys_unittest.cc.
[email protected]e5e894ff2012-09-06 02:18:4710#include <string>
11
Sharon Yang41d26ed2021-01-14 21:23:5212#include "build/build_config.h"
David Dorwin581738b2022-10-28 10:40:5013#include "build/chromeos_buildflags.h"
David Dorwinc5f373c2022-09-12 19:11:4814#include "google_apis/buildflags.h"
Sharon Yang41d26ed2021-01-14 21:23:5215
[email protected]e5e894ff2012-09-06 02:18:4716// These functions enable you to retrieve keys to use for Google APIs
17// such as Translate and Safe Browsing.
18//
19// You can retrieve either an "API key" (sometimes called a developer
20// key) which identifies you (or the company you work for) as a
21// developer, or you can retrieve the "client ID" and "client secret"
22// used by you (or the company you work for) to generate OAuth2
23// requests.
24//
25// Each developer (or group of developers working together for a
26// single company) must request a Google API key and the client ID and
27// client secret for OAuth2. See
28// https://developers.google.com/console/help/ and
29// https://developers.google.com/console/.
30//
Alex Ilin9ac2a9c2020-07-06 14:28:5531// The keys must either be provided using preprocessor variables (set via e.g.
32// GN args). Alternatively, they can be overridden at runtime using one of the
33// following methods (in priority order):
34// - Command line parameters (only for GOOGLE_CLIENT_ID_MAIN and
35// GOOGLE_CLIENT_SECRET_MAIN values). The command-line parameters are
36// --oauth2-client-id and --oauth2-client-secret.
37// - Config file entry of the same name. Path to a config file is set via the
38// --gaia-config command line parameter. See google_apis/gaia/gaia_config.h
39// for syntax reference.
40// - Environment variables of the same name. Environment variable overrides will
41// be ignored for official Google Chrome builds.
[email protected]e5e894ff2012-09-06 02:18:4742//
43// The names of the preprocessor variables (or environment variables
robertshield8d06e9e2017-06-23 14:09:1844// to override them at runtime in Chromium builds) are as follows:
[email protected]e5e894ff2012-09-06 02:18:4745// - GOOGLE_API_KEY: The API key, a.k.a. developer key.
46// - GOOGLE_DEFAULT_CLIENT_ID: If set, this is used as the default for
47// all client IDs not otherwise set. This is intended only for
48// development.
49// - GOOGLE_DEFAULT_CLIENT_SECRET: If set, this is used as the default
50// for all client secrets. This is intended only for development.
51// - GOOGLE_CLIENT_ID_[client name]
[email protected]e5e894ff2012-09-06 02:18:4752// - GOOGLE_CLIENT_SECRET_[client name]
Lei Zhang2c1a1e542022-01-21 19:41:4353// (e.g. GOOGLE_CLIENT_SECRET_REMOTING, i.e. one for each item in
[email protected]e5e894ff2012-09-06 02:18:4754// the OAuth2Client enumeration below)
55//
[email protected]e5e894ff2012-09-06 02:18:4756// 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
62namespace google_apis {
63
dzhioevbd0661412015-10-20 23:00:0764extern const char kAPIKeysDevelopersHowToURL[];
65
Mihai Sardarescu806c35402018-06-20 17:01:0666// Returns true if no dummy API key is set.
67bool HasAPIKeyConfigured();
[email protected]e7dd7892013-05-16 19:10:4068
69// Retrieves the API key, a.k.a. developer key, or a dummy string
[email protected]e5e894ff2012-09-06 02:18:4770// 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.
74std::string GetAPIKey();
75
jkrcalf7baf812016-03-22 10:23:4276// Non-stable channels may have a different Google API key.
77std::string GetNonStableAPIKey();
78
Yuwei Huang701d20932019-05-10 22:19:0279// Retrieves the Chrome Remote Desktop API key.
80std::string GetRemotingAPIKey();
Yuwei Huang48b145e72019-02-13 19:07:2681
David Dorwin97f1a032022-11-02 21:44:0382// Retrieves the Speech On-Device API (SODA) API Key.
83std::string GetSodaAPIKey();
84
David Dorwin581738b2022-10-28 10:40:5085#if BUILDFLAG(IS_CHROMEOS_ASH)
Himanshu Jaju6d021882020-01-23 10:32:4886// Retrieves the Sharing API Key.
87std::string GetSharingAPIKey();
evliudcab7132020-07-23 09:17:2188
Joel Riley43ccd762021-06-04 20:25:5789// Retrieves the ReadAloud API Key.
90std::string GetReadAloudAPIKey();
91
Hirthanan Subenderan658abca42021-12-02 19:22:1792// Retrieves the Fresnel API Key.
93std::string GetFresnelAPIKey();
David Dorwin97f1a032022-11-02 21:44:0394#endif
Hirthanan Subenderan658abca42021-12-02 19:22:1795
David Dorwinc5f373c2022-09-12 19:11:4896#if BUILDFLAG(SUPPORT_EXTERNAL_GOOGLE_API_KEY)
jzw2d2920822017-04-20 09:19:2997// Sets the API key. This should be called as early as possible before this
Sharon Yang41d26ed2021-01-14 21:23:5298// API key is even accessed. It must be called before GetAPIKey.
99// TODO(https://crbug.com/1166007): Enforce this is called before GetAPIKey.
jzw2d2920822017-04-20 09:19:29100void SetAPIKey(const std::string& api_key);
101#endif
102
Jesse Dohertybc473b42019-02-14 16:05:34103// Retrieves the key used to sign metrics (UMA/UKM) uploads.
104std::string GetMetricsKey();
105
[email protected]e5e894ff2012-09-06 02:18:47106// Represents the different sets of client IDs and secrets in use.
107enum OAuth2Client {
Lei Zhang2c1a1e542022-01-21 19:41:43108 CLIENT_MAIN, // Several different features use this.
[email protected]e5e894ff2012-09-06 02:18:47109 CLIENT_REMOTING,
[email protected]d66d81742013-08-16 05:18:38110 CLIENT_REMOTING_HOST,
[email protected]e5e894ff2012-09-06 02:18:47111
Lei Zhang2c1a1e542022-01-21 19:41:43112 CLIENT_NUM_ITEMS // Must be last item.
[email protected]e5e894ff2012-09-06 02:18:47113};
114
Mihai Sardarescu806c35402018-06-20 17:01:06115// Returns true if no dummy OAuth2 client ID and secret are set.
116bool HasOAuthClientConfigured();
117
[email protected]e5e894ff2012-09-06 02:18:47118// Retrieves the OAuth2 client ID for the specified client, or the
119// empty string if not set.
120//
121// Note that the ID should be escaped for the context you use it in,
122// e.g. URL-escaped if you use it in a URL.
123std::string GetOAuth2ClientID(OAuth2Client client);
124
125// Retrieves the OAuth2 client secret for the specified client, or the
126// empty string if not set.
127//
128// Note that the secret should be escaped for the context you use it
129// in, e.g. URL-escaped if you use it in a URL.
130std::string GetOAuth2ClientSecret(OAuth2Client client);
131
Xiaohan Wang83bdf142022-01-21 19:23:11132#if BUILDFLAG(IS_IOS)
jzw2d2920822017-04-20 09:19:29133// Sets the client id for the specified client. Should be called as early as
134// possible before these ids are accessed.
135void SetOAuth2ClientID(OAuth2Client client, const std::string& client_id);
136
137// Sets the client secret for the specified client. Should be called as early as
138// possible before these secrets are accessed.
139void SetOAuth2ClientSecret(OAuth2Client client,
140 const std::string& client_secret);
141#endif
kundaji033fb6ec2014-10-15 19:11:08142
[email protected]e4b54e32014-01-17 13:55:20143// Returns if the API key using in the current build is the one for official
144// Google Chrome.
145bool IsGoogleChromeAPIKeyUsed();
146
[email protected]e5e894ff2012-09-06 02:18:47147} // namespace google_apis
148
[email protected]6386cf52012-09-07 04:26:37149#endif // GOOGLE_APIS_GOOGLE_API_KEYS_H_