@@ -6,7 +6,11 @@ Authentication
6
6
Overview
7
7
========
8
8
9
- * **If you're running in Compute Engine or App Engine **,
9
+ For a language agnostic overview of authentication on Google Cloud, see `Authentication Overview `_.
10
+
11
+ .. _Authentication Overview : https://cloud.google.com/docs/authentication
12
+
13
+ * **If you're running in a Google Virtual Machine Environment (Compute Engine, App Engine, Cloud Run, Cloud Functions) **,
10
14
authentication should "just work".
11
15
12
16
* **If you're developing locally **,
@@ -41,7 +45,7 @@ Overview
41
45
42
46
$ export GOOGLE_APPLICATION_CREDENTIALS=" /path/to/keyfile.json"
43
47
44
- .. _service account : https://cloud.google.com/storage /docs/authentication#generating-a-private-key
48
+ .. _service account : https://cloud.google.com/iam /docs/creating-managing-service-accounts#creating
45
49
46
50
Client-Provided Authentication
47
51
==============================
@@ -97,11 +101,17 @@ After creation, you can pass it directly to a :class:`Client <google.cloud.clien
97
101
.. tip ::
98
102
To create a credentials object, follow the `google-auth-guide `_.
99
103
100
- .. _google-auth-guide : https://google-auth.readthedocs.io/en/latest/user-guide.html#service-account-private-key-files
104
+ .. _google-auth-guide : https://googleapis.dev/python/google-auth/latest/user-guide.html#service-account-private-key-files
105
+
101
106
107
+ Google App Engine Standard First Generation Environment
108
+ -------------------------------------------------------
109
+
110
+ These credentials are used only in the legacy Python 2.7
111
+ `First Generation Standard Environment `_. All other App Engine
112
+ runtimes use Compute Engine credentials.
102
113
103
- Google App Engine Environment
104
- -----------------------------
114
+ .. _First Generation Standard Environment : https://cloud.google.com/appengine/docs/standard/runtimes
105
115
106
116
To create
107
117
:class: `credentials <google.auth.app_engine.Credentials> `
@@ -115,9 +125,12 @@ just for Google App Engine:
115
125
Google Compute Engine Environment
116
126
---------------------------------
117
127
128
+ These credentials are used in Google Virtual Machine Environments.
129
+ This includes most App Engine runtimes, Compute Engine, Cloud
130
+ Functions, and Cloud Run.
131
+
118
132
To create
119
- :class: `credentials <google.auth.compute_engine.Credentials> `
120
- just for Google Compute Engine:
133
+ :class: `credentials <google.auth.compute_engine.Credentials> `:
121
134
122
135
.. code :: python
123
136
@@ -129,16 +142,24 @@ Service Accounts
129
142
130
143
A `service account `_ is stored in a JSON keyfile.
131
144
132
- The
133
- :meth: `from_service_account_json() <google.cloud.client.Client.from_service_account_json> `
134
- factory can be used to create a :class: `Client <google.cloud.client.Client> ` with
135
- service account credentials.
145
+ .. code :: python
146
+
147
+ from google.oauth2 import service_account
148
+
149
+ credentials = service_account.Credentials.from_service_account_file(
150
+ ' /path/to/key.json' )
136
151
137
- For example, with a JSON keyfile :
152
+ A JSON string or dictionary :
138
153
139
154
.. code :: python
140
155
141
- client = Client.from_service_account_json(' /path/to/keyfile.json' )
156
+ import json
157
+
158
+ from google.oauth2 import service_account
159
+
160
+ json_account_info = json.loads(... ) # convert JSON to dictionary
161
+ credentials = service_account.Credentials.from_service_account_info(
162
+ json_account_info)
142
163
143
164
.. tip ::
144
165
@@ -160,7 +181,7 @@ possible to call Google Cloud APIs with a user account via
160
181
161
182
A production application should **use a service account **,
162
183
but you may wish to use your own personal user account when first
163
- getting started with the ``google-cloud-python `` library.
184
+ getting started with the ``google-cloud-* `` library.
164
185
165
186
The simplest way to use credentials from a user account is via
166
187
Application Default Credentials using ``gcloud auth login ``
@@ -183,67 +204,10 @@ Troubleshooting
183
204
Setting up a Service Account
184
205
----------------------------
185
206
186
- If your application is not running on Google Compute Engine,
187
- you need a `Google Developers Service Account `_.
188
-
189
- #. Visit the `Google Developers Console `_.
190
-
191
- #. Create a new project or click on an existing project.
192
-
193
- #. Navigate to **APIs & auth ** > **APIs ** and enable the APIs
194
- that your application requires.
195
-
196
- .. raw :: html
197
-
198
- <img src =" https://raw.githubusercontent.com/GoogleCloudPlatform/google-cloud-common/master/authentication/enable-apis.png" />
199
-
200
- .. note ::
201
-
202
- You may need to enable billing in order to use these services.
203
-
204
- * **BigQuery **
205
-
206
- * BigQuery API
207
-
208
- * **Datastore **
209
-
210
- * Google Cloud Datastore API
207
+ If your application is not running on a Google Virtual Machine Environment,
208
+ you need a Service Account. See `Creating a Service Account `_.
211
209
212
- * **Pub/Sub **
213
-
214
- * Google Cloud Pub/Sub
215
-
216
- * **Storage **
217
-
218
- * Google Cloud Storage
219
- * Google Cloud Storage JSON API
220
-
221
- #. Navigate to **APIs & auth ** > **Credentials **.
222
-
223
- You should see a screen like one of the following:
224
-
225
- .. raw :: html
226
-
227
- <img src =" https://raw.githubusercontent.com/GoogleCloudPlatform/google-cloud-common/master/authentication/create-new-service-account.png" >
228
-
229
- .. raw :: html
230
-
231
- <img src =" https://raw.githubusercontent.com/GoogleCloudPlatform/google-cloud-common/master/authentication/create-new-service-account-existing-keys.png" >
232
-
233
- Find the "Add credentials" drop down and select "Service account" to be
234
- guided through downloading a new JSON keyfile.
235
-
236
- If you want to re-use an existing service account,
237
- you can easily generate a new keyfile.
238
- Just select the account you wish to re-use,
239
- and click **Generate new JSON key **:
240
-
241
- .. raw :: html
242
-
243
- <img src =" https://raw.githubusercontent.com/GoogleCloudPlatform/google-cloud-common/master/authentication/reuse-service-account.png" >
244
-
245
- .. _Google Developers Console : https://console.developers.google.com/project
246
- .. _Google Developers Service Account : https://developers.google.com/accounts/docs/OAuth2ServiceAccount
210
+ .. _Creating a Service Account : https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating
247
211
248
212
Using Google Compute Engine
249
213
---------------------------
@@ -262,24 +226,7 @@ you add the correct scopes for the APIs you want to access:
262
226
* ``https://www.googleapis.com/auth/cloud-platform ``
263
227
* ``https://www.googleapis.com/auth/cloud-platform.read-only ``
264
228
265
- * **BigQuery **
266
-
267
- * ``https://www.googleapis.com/auth/bigquery ``
268
- * ``https://www.googleapis.com/auth/bigquery.insertdata ``
269
-
270
- * **Datastore **
271
-
272
- * ``https://www.googleapis.com/auth/datastore ``
273
- * ``https://www.googleapis.com/auth/userinfo.email ``
274
-
275
- * **Pub/Sub **
276
-
277
- * ``https://www.googleapis.com/auth/pubsub ``
278
-
279
- * **Storage **
280
-
281
- * ``https://www.googleapis.com/auth/devstorage.full_control ``
282
- * ``https://www.googleapis.com/auth/devstorage.read_only ``
283
- * ``https://www.googleapis.com/auth/devstorage.read_write ``
229
+ For scopes for specific APIs see `OAuth 2.0 Scopes for Google APIs `_
284
230
285
231
.. _set up the GCE instance : https://cloud.google.com/compute/docs/authentication#using
232
+ .. _OAuth 2.0 Scopes for Google APIS : https://developers.google.com/identity/protocols/oauth2/scopes
0 commit comments