Ben Henry | 95c0220f | 2021-05-10 15:59:20 | [diff] [blame] | 1 | # API Keys |
| 2 | |
| 3 | When using a custom build, fork, or integration of Chromium, or if you're |
| 4 | building 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 |
| 10 | the keys themselves cannot be shared with parties outside the legal entity that |
| 11 | accepted the API ToS. Keep in mind that a number of the APIs will have no or |
| 12 | very limited quota and not all of the APIs have additional quota available for |
| 13 | purchase. |
| 14 | *** |
| 15 | |
| 16 | **Googlers only:** |
| 17 | |
| 18 | * For a simpler approach to API keys, see https://go/chrome-api-key-setup |
| 19 | * If you need a new API enabled in Chrome, use https://b/new?component=165132 |
| 20 | |
| 21 | **How-to:** |
| 22 | First, acquire API keys. Then, specify the API keys to use either when you build |
| 23 | Chromium, or at runtime using environment variables. |
| 24 | |
| 25 | ## Acquiring Keys |
| 26 | |
| 27 | 1. 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 | *** |
| 32 | 1. Make sure you are logged in with the Google account associated with the email |
| 33 | address that you used to subscribe to chromium-dev. |
| 34 | 1. Go to https://cloud.google.com/console |
| 35 | 1. _optional_ You may add other members of your organization or team on the Team |
| 36 | tab. |
| 37 | 1. 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) |
| 55 | * Safe Browsing API |
| 56 | * Time Zone API |
| 57 | * Optional |
| 58 | * Admin SDK |
| 59 | * Cloud Translation API |
| 60 | * Geocoding API |
| 61 | * Google Assistant API |
| 62 | * Google Calendar API |
| 63 | * Nearby Messages API |
| 64 | |
| 65 | 1. Go to the **Credentials** sub tab under the **API & Services** section in the |
| 66 | hamburger menu. |
| 67 | 1. Click the `Create credentials` button then click on the **OAuth client |
| 68 | ID** item in the drop-down list. |
| 69 | * Click on the `Configure consent screen` button. Fill in the "product |
| 70 | name" (anything you choose) and other details, then click on `Save`. |
| 71 | * Return to the Credentials tab and click the `Add credentials` button |
| 72 | again, then select "OAuth 2.0 client ID" from the drop-down list. |
| 73 | * In the "Application type" section check the **Other** option and give it a |
| 74 | name in the "Name" text box, then click `Create`. |
| 75 | 1. In the pop-up window that appears, you'll see a **client ID** and a **Client |
| 76 | secret** string. Copy and paste those in a text file on your dev box then |
| 77 | click `OK` to dismiss. A new item should now appear in the **OAuth 2.0 client |
| 78 | IDs** list. You can click on the name of your client ID to retrieve the ID and |
| 79 | secret at any time. In the next few sections, these values will be referred |
| 80 | to as the **Client ID** and **Client secret** fields. |
| 81 | 1. Click the `Create credentials` button _again_ on the same page. |
| 82 | * In the pop-over window that shows up, click the `API key` button. |
| 83 | * A pop-over should show up giving you the API key. Copy/paste in to a text |
| 84 | file to save, although you will be able to access this as well. |
| 85 | * Click `OK` to dismiss. |
| 86 | |
| 87 | You should now have an API key and an OAuth 2.0 client ID in the **Credentials** |
| 88 | tab. The next sections will refer to the value as the "API key". |
| 89 | |
| 90 | *** note |
| 91 | **Note:** Your keys are not for distribution, and should not be shared with |
| 92 | others. |
| 93 | *** |
| 94 | |
| 95 | ## Providing Keys at Build time |
| 96 | |
| 97 | If you are building Chromium yourself, you can provide keys as part of your |
| 98 | build configuration, that way they are always baked into your binary. |
| 99 | |
| 100 | Specify three variables in your `args.gn` file (edit by running `gn args |
| 101 | out/your_out_dir_here`) |
| 102 | |
| 103 | ```bash |
| 104 | google_api_key = "your_api_key" |
| 105 | google_default_client_id = "your_client_id" |
| 106 | google_default_client_secret = "your_client_secret" |
| 107 | ``` |
| 108 | |
| 109 | ## Providing Keys at Runtime |
| 110 | |
| 111 | If you prefer, you can build a Chromium binary (or use a pre-built Chromium |
| 112 | binary) without API keys baked in, and instead provide them at runtime. To do |
| 113 | so, set the environment variables `GOOGLE_API_KEY`, `GOOGLE_DEFAULT_CLIENT_ID` |
| 114 | and `GOOGLE_DEFAULT_CLIENT_SECRET` to your "API key", "Client ID" and "Client |
| 115 | secret" values respectively. |
| 116 | |
| 117 | On Chromium OS to specify the keys as environment variables append them to the |
| 118 | end of `/etc/chrome_dev.conf`: |
| 119 | |
| 120 | ```bash |
| 121 | GOOGLE_API_KEY=your_api_key |
| 122 | GOOGLE_DEFAULT_CLIENT_ID=your_client_id |
| 123 | GOOGLE_DEFAULT_CLIENT_SECRET=your_client_secret |
| 124 | ``` |
| 125 | |
| 126 | ## Signing in to Chromium is restricted |
| 127 | |
| 128 | Signing in to Chromium requires an OAuth 2.0 token for authentication. As this |
| 129 | OAuth 2.0 token gives access to various Google services that handle user data |
| 130 | (e.g. Chrome sync), for security and privacy reasons the generation of this |
| 131 | OAuth 2.0 token is restricted. This means that signing in to Chromium is |
| 132 | restricted (as the OAuth 2.0 token cannot be generated). In order to sign in to |
| 133 | Chromium builds, please add your test account to |
| 134 | [email protected] (accounts in this group are |
| 135 | allowed to get access tokens bypassing the restriction above). |
| 136 | |
| 137 | *** note |
| 138 | **Note:** Starting with Chromium M69, when the browser is set up with an OAuth |
| 139 | 2.0 client ID and client secret, signing in with your Google Account to any |
| 140 | Google web property will also attempt to sign you in to Chromium (which will |
| 141 | fail as explained above). To avoid such errors, remove your OAuth 2.0 client |
| 142 | ID and client secret from your build to stop generating tokens when users sign |
| 143 | in to Google web properties (remove `google_default_client_id`, |
| 144 | `google_default_client_secret` from gn args and `GOOGLE_DEFAULT_CLIENT_ID` |
| 145 | and `GOOGLE_DEFAULT_CLIENT_SECRET` from your environment settings). |
| 146 | *** |
| 147 | |
| 148 | ## Getting Keys for Your Chromium Derivative |
| 149 | |
| 150 | Many of the Google APIs used by Chrome are specific to Google and not intended |
| 151 | for use in derived products. In the [API Console](http://developers.google.com/console) |
| 152 | you may be able to purchase additional quota for some of the APIs listed above. |
| 153 | **For APIs that do not have a "Pricing" link, additional quota is not available |
| 154 | for purchase.** |
| 155 | |
| 156 | ## Polyfilling chrome.identity API in Your Chromium Derivative |
| 157 | |
| 158 | The default Chromium `chrome.identity.getAuthToken` API that extensions may |
| 159 | call to obtain auth tokens will fail outside of Google Chrome as the |
| 160 | implementation uses restricted APIs. |
| 161 | |
| 162 | A prototype CL for Chromium embedders might use to replace the implementation |
| 163 | with one not dependent upon private APIs can be found attached to |
| 164 | [this post](https://groups.google.com/a/chromium.org/g/embedder-dev/c/tGCJ3QNVzYE). |