blob: d8f7079a29faeeddd6f7703bd6986e6324731675 [file] [log] [blame] [view]
Ben Henry95c0220f2021-05-10 15:59:201# API Keys
2
3When using a custom build, fork, or integration of Chromium, or if you're
4building ChromiumOS, you will need access to Google API for key functionality.
5
6[TOC]
7
8*** note
9**Note:** Software distribution with keys acquired for yourself is allowed, but
10the keys themselves cannot be shared with parties outside the legal entity that
11accepted the API ToS. Keep in mind that a number of the APIs will have no or
12very limited quota and not all of the APIs have additional quota available for
13purchase.
14***
15
16**Googlers only:**
17
Trevor Perrierda3d6622025-05-02 17:43:1418* For a simpler approach to API keys, see http://go/chrome-api-key-setup
19* If you need a new API enabled in Chrome, use http://b/new?component=165132
Ben Henry95c0220f2021-05-10 15:59:2020
21**How-to:**
22First, acquire API keys. Then, specify the API keys to use either when you build
23Chromium, or at runtime using environment variables.
24
25## Acquiring Keys
26
271. Make sure you are a member of [email protected] (you can choose
28 not to receive mail).
29 *** note
30 **Note:** the APIs below are only visible to people subscribed to that group.
31 ***
321. Make sure you are logged in with the Google account associated with the email
33 address that you used to subscribe to chromium-dev.
341. Go to https://cloud.google.com/console
351. _optional_ You may add other members of your organization or team on the Team
36 tab.
371. Open the **APIs and Services > Library** from the hamburger menu, search for
38 all of the following APIs. For each of these APIs:
39 1. Click on it
40 1. Click `Enable API` button at the top
41 1. Read and agree to the Terms of Service
42 1. Check the `I have read and agree to the <API name> Terms of Service`
43 checkbox
44 1. Click Accept.
45
46 **List of APIs** (if any are not shown, recheck step 1 above):
47
48 * Cloud Search API
49 * Geolocation API (requires [enabling
50 billing](https://developers.google.com/console/help/#EnableBilling) but
51 is free to use; you can skip this one, in which case geolocation features
52 of Chrome will not work)
53 * Google Drive API (enable this for Files.app on Chrome OS and
54 SyncFileSystem API)
thefroga42deb22025-04-29 19:28:0255 * Safe Browsing API (Googlers should additionally reach out to the Safe
56 Browsing team to ensure that visibility labels are applied
57 appropriately)
Ben Henry95c0220f2021-05-10 15:59:2058 * Time Zone API
59 * Optional
60 * Admin SDK
61 * Cloud Translation API
62 * Geocoding API
63 * Google Assistant API
64 * Google Calendar API
65 * Nearby Messages API
66
671. Go to the **Credentials** sub tab under the **API & Services** section in the
68 hamburger menu.
691. Click the `Create credentials` button then click on the **OAuth client
70 ID** item in the drop-down list.
71 * Click on the `Configure consent screen` button. Fill in the "product
72 name" (anything you choose) and other details, then click on `Save`.
73 * Return to the Credentials tab and click the `Add credentials` button
74 again, then select "OAuth 2.0 client ID" from the drop-down list.
75 * In the "Application type" section check the **Other** option and give it a
76 name in the "Name" text box, then click `Create`.
771. In the pop-up window that appears, you'll see a **client ID** and a **Client
78 secret** string. Copy and paste those in a text file on your dev box then
79 click `OK` to dismiss. A new item should now appear in the **OAuth 2.0 client
80 IDs** list. You can click on the name of your client ID to retrieve the ID and
81 secret at any time. In the next few sections, these values will be referred
82 to as the **Client ID** and **Client secret** fields.
831. Click the `Create credentials` button _again_ on the same page.
84 * In the pop-over window that shows up, click the `API key` button.
85 * A pop-over should show up giving you the API key. Copy/paste in to a text
86 file to save, although you will be able to access this as well.
87 * Click `OK` to dismiss.
88
89You should now have an API key and an OAuth 2.0 client ID in the **Credentials**
90tab. The next sections will refer to the value as the "API key".
91
92*** note
93**Note:** Your keys are not for distribution, and should not be shared with
94others.
95***
96
97## Providing Keys at Build time
98
99If you are building Chromium yourself, you can provide keys as part of your
100build configuration, that way they are always baked into your binary.
101
102Specify three variables in your `args.gn` file (edit by running `gn args
103out/your_out_dir_here`)
104
105```bash
106google_api_key = "your_api_key"
107google_default_client_id = "your_client_id"
108google_default_client_secret = "your_client_secret"
109```
110
111## Providing Keys at Runtime
112
113If you prefer, you can build a Chromium binary (or use a pre-built Chromium
114binary) without API keys baked in, and instead provide them at runtime. To do
115so, set the environment variables `GOOGLE_API_KEY`, `GOOGLE_DEFAULT_CLIENT_ID`
116and `GOOGLE_DEFAULT_CLIENT_SECRET` to your "API key", "Client ID" and "Client
117secret" values respectively.
118
119On Chromium OS to specify the keys as environment variables append them to the
120end of `/etc/chrome_dev.conf`:
121
122```bash
123GOOGLE_API_KEY=your_api_key
124GOOGLE_DEFAULT_CLIENT_ID=your_client_id
125GOOGLE_DEFAULT_CLIENT_SECRET=your_client_secret
126```
127
128## Signing in to Chromium is restricted
129
130Signing in to Chromium requires an OAuth 2.0 token for authentication. As this
131OAuth 2.0 token gives access to various Google services that handle user data
132(e.g. Chrome sync), for security and privacy reasons the generation of this
133OAuth 2.0 token is restricted. This means that signing in to Chromium is
134restricted (as the OAuth 2.0 token cannot be generated). In order to sign in to
135Chromium builds, please add your test account to
136[email protected] (accounts in this group are
137allowed to get access tokens bypassing the restriction above).
138
139*** note
140**Note:** Starting with Chromium M69, when the browser is set up with an OAuth
1412.0 client ID and client secret, signing in with your Google Account to any
142Google web property will also attempt to sign you in to Chromium (which will
143fail as explained above). To avoid such errors, remove your OAuth 2.0 client
144ID and client secret from your build to stop generating tokens when users sign
145in to Google web properties (remove `google_default_client_id`,
146`google_default_client_secret` from gn args and `GOOGLE_DEFAULT_CLIENT_ID`
147and `GOOGLE_DEFAULT_CLIENT_SECRET` from your environment settings).
148***
149
150## Getting Keys for Your Chromium Derivative
151
152Many of the Google APIs used by Chrome are specific to Google and not intended
153for use in derived products. In the [API Console](http://developers.google.com/console)
154you may be able to purchase additional quota for some of the APIs listed above.
155**For APIs that do not have a "Pricing" link, additional quota is not available
156for purchase.**
157
158## Polyfilling chrome.identity API in Your Chromium Derivative
159
160The default Chromium `chrome.identity.getAuthToken` API that extensions may
161call to obtain auth tokens will fail outside of Google Chrome as the
162implementation uses restricted APIs.
163
164A prototype CL for Chromium embedders might use to replace the implementation
165with one not dependent upon private APIs can be found attached to
166[this post](https://groups.google.com/a/chromium.org/g/embedder-dev/c/tGCJ3QNVzYE).