blob: bbf45567fbb7e04c3c383a8b66ae91f12cb03806 [file] [log] [blame]
[email protected]e5e894ff2012-09-06 02:18:471// 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]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"
13
[email protected]e5e894ff2012-09-06 02:18:4714// 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 Ilin9ac2a9c2020-07-06 14:28:5529// 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]e5e894ff2012-09-06 02:18:4740//
41// The names of the preprocessor variables (or environment variables
robertshield8d06e9e2017-06-23 14:09:1842// to override them at runtime in Chromium builds) are as follows:
[email protected]e5e894ff2012-09-06 02:18:4743// - 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]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
Himanshu Jaju6d021882020-01-23 10:32:4882// Retrieves the Sharing API Key.
83std::string GetSharingAPIKey();
84
evliudcab7132020-07-23 09:17:2185// Retrieves the Speech On-Device API (SODA) API Key.
86std::string GetSodaAPIKey();
87
Sharon Yang41d26ed2021-01-14 21:23:5288#if defined(OS_IOS) || defined(OS_FUCHSIA)
jzw2d2920822017-04-20 09:19:2989// Sets the API key. This should be called as early as possible before this
Sharon Yang41d26ed2021-01-14 21:23:5290// API key is even accessed. It must be called before GetAPIKey.
91// TODO(https://crbug.com/1166007): Enforce this is called before GetAPIKey.
jzw2d2920822017-04-20 09:19:2992void SetAPIKey(const std::string& api_key);
93#endif
94
Jesse Dohertybc473b42019-02-14 16:05:3495// Retrieves the key used to sign metrics (UMA/UKM) uploads.
96std::string GetMetricsKey();
97
[email protected]e5e894ff2012-09-06 02:18:4798// Represents the different sets of client IDs and secrets in use.
99enum OAuth2Client {
100 CLIENT_MAIN, // Several different features use this.
101 CLIENT_CLOUD_PRINT,
102 CLIENT_REMOTING,
[email protected]d66d81742013-08-16 05:18:38103 CLIENT_REMOTING_HOST,
[email protected]e5e894ff2012-09-06 02:18:47104
105 CLIENT_NUM_ITEMS // Must be last item.
106};
107
Mihai Sardarescu806c35402018-06-20 17:01:06108// Returns true if no dummy OAuth2 client ID and secret are set.
109bool HasOAuthClientConfigured();
110
[email protected]e5e894ff2012-09-06 02:18:47111// 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.
116std::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.
123std::string GetOAuth2ClientSecret(OAuth2Client client);
124
jzw2d2920822017-04-20 09:19:29125#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.
128void 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.
132void SetOAuth2ClientSecret(OAuth2Client client,
133 const std::string& client_secret);
134#endif
kundaji033fb6ec2014-10-15 19:11:08135// Returns the auth token for the data reduction proxy.
136std::string GetSpdyProxyAuthValue();
137
[email protected]e4b54e32014-01-17 13:55:20138// Returns if the API key using in the current build is the one for official
139// Google Chrome.
140bool IsGoogleChromeAPIKeyUsed();
141
[email protected]e5e894ff2012-09-06 02:18:47142} // namespace google_apis
143
[email protected]6386cf52012-09-07 04:26:37144#endif // GOOGLE_APIS_GOOGLE_API_KEYS_H_