blob: ba958fcfb2d7bb12e9d4b471f2d00152654cf264 [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
Mikel Astiza08ea662023-02-21 19:30:1112#include "base/component_export.h"
Sharon Yang41d26ed2021-01-14 21:23:5213#include "build/build_config.h"
David Dorwin581738b2022-10-28 10:40:5014#include "build/chromeos_buildflags.h"
David Dorwinc5f373c2022-09-12 19:11:4815#include "google_apis/buildflags.h"
Sharon Yang41d26ed2021-01-14 21:23:5216
[email protected]e5e894ff2012-09-06 02:18:4717// These functions enable you to retrieve keys to use for Google APIs
18// such as Translate and Safe Browsing.
19//
20// You can retrieve either an "API key" (sometimes called a developer
21// key) which identifies you (or the company you work for) as a
22// developer, or you can retrieve the "client ID" and "client secret"
23// used by you (or the company you work for) to generate OAuth2
24// requests.
25//
26// Each developer (or group of developers working together for a
27// single company) must request a Google API key and the client ID and
28// client secret for OAuth2. See
29// https://developers.google.com/console/help/ and
30// https://developers.google.com/console/.
31//
Alex Ilin9ac2a9c2020-07-06 14:28:5532// The keys must either be provided using preprocessor variables (set via e.g.
33// GN args). Alternatively, they can be overridden at runtime using one of the
34// following methods (in priority order):
35// - Command line parameters (only for GOOGLE_CLIENT_ID_MAIN and
36// GOOGLE_CLIENT_SECRET_MAIN values). The command-line parameters are
37// --oauth2-client-id and --oauth2-client-secret.
38// - Config file entry of the same name. Path to a config file is set via the
39// --gaia-config command line parameter. See google_apis/gaia/gaia_config.h
40// for syntax reference.
41// - Environment variables of the same name. Environment variable overrides will
42// be ignored for official Google Chrome builds.
[email protected]e5e894ff2012-09-06 02:18:4743//
44// The names of the preprocessor variables (or environment variables
robertshield8d06e9e2017-06-23 14:09:1845// to override them at runtime in Chromium builds) are as follows:
[email protected]e5e894ff2012-09-06 02:18:4746// - GOOGLE_API_KEY: The API key, a.k.a. developer key.
47// - GOOGLE_DEFAULT_CLIENT_ID: If set, this is used as the default for
48// all client IDs not otherwise set. This is intended only for
49// development.
50// - GOOGLE_DEFAULT_CLIENT_SECRET: If set, this is used as the default
51// for all client secrets. This is intended only for development.
52// - GOOGLE_CLIENT_ID_[client name]
[email protected]e5e894ff2012-09-06 02:18:4753// - GOOGLE_CLIENT_SECRET_[client name]
Lei Zhang2c1a1e542022-01-21 19:41:4354// (e.g. GOOGLE_CLIENT_SECRET_REMOTING, i.e. one for each item in
[email protected]e5e894ff2012-09-06 02:18:4755// the OAuth2Client enumeration below)
56//
[email protected]e5e894ff2012-09-06 02:18:4757// If some of the parameters mentioned above are not provided,
58// Chromium will still build and run, but services that require them
59// may fail to work without warning. They should do so gracefully,
60// similar to what would happen when a network connection is
61// unavailable.
62
63namespace google_apis {
64
Mikel Astiza08ea662023-02-21 19:30:1165COMPONENT_EXPORT(GOOGLE_APIS) extern const char kAPIKeysDevelopersHowToURL[];
dzhioevbd0661412015-10-20 23:00:0766
Mihai Sardarescu806c35402018-06-20 17:01:0667// Returns true if no dummy API key is set.
Mikel Astiza08ea662023-02-21 19:30:1168COMPONENT_EXPORT(GOOGLE_APIS) bool HasAPIKeyConfigured();
[email protected]e7dd7892013-05-16 19:10:4069
70// Retrieves the API key, a.k.a. developer key, or a dummy string
[email protected]e5e894ff2012-09-06 02:18:4771// if not set.
72//
73// Note that the key should be escaped for the context you use it in,
74// e.g. URL-escaped if you use it in a URL.
Mikel Astiza08ea662023-02-21 19:30:1175COMPONENT_EXPORT(GOOGLE_APIS) std::string GetAPIKey();
[email protected]e5e894ff2012-09-06 02:18:4776
jkrcalf7baf812016-03-22 10:23:4277// Non-stable channels may have a different Google API key.
Mikel Astiza08ea662023-02-21 19:30:1178COMPONENT_EXPORT(GOOGLE_APIS) std::string GetNonStableAPIKey();
jkrcalf7baf812016-03-22 10:23:4279
Yuwei Huang701d20932019-05-10 22:19:0280// Retrieves the Chrome Remote Desktop API key.
Mikel Astiza08ea662023-02-21 19:30:1181COMPONENT_EXPORT(GOOGLE_APIS) std::string GetRemotingAPIKey();
Yuwei Huang48b145e72019-02-13 19:07:2682
David Dorwin97f1a032022-11-02 21:44:0383// Retrieves the Speech On-Device API (SODA) API Key.
Mikel Astiza08ea662023-02-21 19:30:1184COMPONENT_EXPORT(GOOGLE_APIS) std::string GetSodaAPIKey();
David Dorwin97f1a032022-11-02 21:44:0385
David Dorwin581738b2022-10-28 10:40:5086#if BUILDFLAG(IS_CHROMEOS_ASH)
Himanshu Jaju6d021882020-01-23 10:32:4887// Retrieves the Sharing API Key.
Mikel Astiza08ea662023-02-21 19:30:1188COMPONENT_EXPORT(GOOGLE_APIS) std::string GetSharingAPIKey();
evliudcab7132020-07-23 09:17:2189
Joel Riley43ccd762021-06-04 20:25:5790// Retrieves the ReadAloud API Key.
Mikel Astiza08ea662023-02-21 19:30:1191COMPONENT_EXPORT(GOOGLE_APIS) std::string GetReadAloudAPIKey();
Joel Riley43ccd762021-06-04 20:25:5792
Hirthanan Subenderan658abca42021-12-02 19:22:1793// Retrieves the Fresnel API Key.
Mikel Astiza08ea662023-02-21 19:30:1194COMPONENT_EXPORT(GOOGLE_APIS) std::string GetFresnelAPIKey();
David Dorwin97f1a032022-11-02 21:44:0395#endif
Hirthanan Subenderan658abca42021-12-02 19:22:1796
David Dorwinc5f373c2022-09-12 19:11:4897#if BUILDFLAG(SUPPORT_EXTERNAL_GOOGLE_API_KEY)
jzw2d2920822017-04-20 09:19:2998// Sets the API key. This should be called as early as possible before this
Sharon Yang41d26ed2021-01-14 21:23:5299// API key is even accessed. It must be called before GetAPIKey.
100// TODO(https://crbug.com/1166007): Enforce this is called before GetAPIKey.
Mikel Astiza08ea662023-02-21 19:30:11101COMPONENT_EXPORT(GOOGLE_APIS) void SetAPIKey(const std::string& api_key);
jzw2d2920822017-04-20 09:19:29102#endif
103
Jesse Dohertybc473b42019-02-14 16:05:34104// Retrieves the key used to sign metrics (UMA/UKM) uploads.
Mikel Astiza08ea662023-02-21 19:30:11105COMPONENT_EXPORT(GOOGLE_APIS) std::string GetMetricsKey();
Jesse Dohertybc473b42019-02-14 16:05:34106
[email protected]e5e894ff2012-09-06 02:18:47107// Represents the different sets of client IDs and secrets in use.
108enum OAuth2Client {
Lei Zhang2c1a1e542022-01-21 19:41:43109 CLIENT_MAIN, // Several different features use this.
[email protected]e5e894ff2012-09-06 02:18:47110 CLIENT_REMOTING,
[email protected]d66d81742013-08-16 05:18:38111 CLIENT_REMOTING_HOST,
[email protected]e5e894ff2012-09-06 02:18:47112
Lei Zhang2c1a1e542022-01-21 19:41:43113 CLIENT_NUM_ITEMS // Must be last item.
[email protected]e5e894ff2012-09-06 02:18:47114};
115
Mihai Sardarescu806c35402018-06-20 17:01:06116// Returns true if no dummy OAuth2 client ID and secret are set.
Mikel Astiza08ea662023-02-21 19:30:11117COMPONENT_EXPORT(GOOGLE_APIS) bool HasOAuthClientConfigured();
Mihai Sardarescu806c35402018-06-20 17:01:06118
[email protected]e5e894ff2012-09-06 02:18:47119// Retrieves the OAuth2 client ID for the specified client, or the
120// empty string if not set.
121//
122// Note that the ID should be escaped for the context you use it in,
123// e.g. URL-escaped if you use it in a URL.
Mikel Astiza08ea662023-02-21 19:30:11124COMPONENT_EXPORT(GOOGLE_APIS)
[email protected]e5e894ff2012-09-06 02:18:47125std::string GetOAuth2ClientID(OAuth2Client client);
126
127// Retrieves the OAuth2 client secret for the specified client, or the
128// empty string if not set.
129//
130// Note that the secret should be escaped for the context you use it
131// in, e.g. URL-escaped if you use it in a URL.
Mikel Astiza08ea662023-02-21 19:30:11132COMPONENT_EXPORT(GOOGLE_APIS)
[email protected]e5e894ff2012-09-06 02:18:47133std::string GetOAuth2ClientSecret(OAuth2Client client);
134
Xiaohan Wang83bdf142022-01-21 19:23:11135#if BUILDFLAG(IS_IOS)
jzw2d2920822017-04-20 09:19:29136// Sets the client id for the specified client. Should be called as early as
137// possible before these ids are accessed.
Mikel Astiza08ea662023-02-21 19:30:11138COMPONENT_EXPORT(GOOGLE_APIS)
jzw2d2920822017-04-20 09:19:29139void SetOAuth2ClientID(OAuth2Client client, const std::string& client_id);
140
141// Sets the client secret for the specified client. Should be called as early as
142// possible before these secrets are accessed.
Mikel Astiza08ea662023-02-21 19:30:11143COMPONENT_EXPORT(GOOGLE_APIS)
jzw2d2920822017-04-20 09:19:29144void SetOAuth2ClientSecret(OAuth2Client client,
145 const std::string& client_secret);
146#endif
kundaji033fb6ec2014-10-15 19:11:08147
[email protected]e4b54e32014-01-17 13:55:20148// Returns if the API key using in the current build is the one for official
149// Google Chrome.
Mikel Astiza08ea662023-02-21 19:30:11150COMPONENT_EXPORT(GOOGLE_APIS) bool IsGoogleChromeAPIKeyUsed();
[email protected]e4b54e32014-01-17 13:55:20151
[email protected]e5e894ff2012-09-06 02:18:47152} // namespace google_apis
153
[email protected]6386cf52012-09-07 04:26:37154#endif // GOOGLE_APIS_GOOGLE_API_KEYS_H_