Skip to content

Commit 94589bc

Browse files
committed
Adding section about order used for app. default creds.
Also adding subsection (<h3>) headers within the material about clients.
1 parent ead33cc commit 94589bc

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

docs/gcloud-auth.rst

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Authentication
2-
--------------
2+
**************
33

44
.. _Overview:
55

@@ -20,13 +20,15 @@ Overview
2020

2121

2222
* **If you're running your application elsewhere**,
23-
you should download a service account JSON keyfile
23+
you should download a `service account`_ JSON keyfile
2424
and point to it using an environment variable:
2525

2626
.. code-block:: bash
2727
2828
$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"
2929
30+
.. _service account: https://cloud.google.com/storage/docs/authentication#generating-a-private-key
31+
3032
Client-Provided Authentication
3133
==============================
3234

@@ -43,3 +45,43 @@ instructions in the :ref:`Overview`. The credentials are inferred from your
4345
local environment by using Google `Application Default Credentials`_.
4446

4547
.. _Application Default Credentials: https://developers.google.com/identity/protocols/application-default-credentials
48+
49+
Credential Discovery Precedence
50+
-------------------------------
51+
52+
When loading the `Application Default Credentials`_, the library will check
53+
properties of your local environment in the following order
54+
55+
#. Application running in Google App Engine
56+
#. JSON or PKCS12/P12 keyfile pointed to by
57+
``GOOGLE_APPLICATION_CREDENTIALS`` environment variable
58+
#. Credentials provided by the Google Cloud SDK (via ``gcloud auth login``)
59+
#. Application running in Google Compute Engine
60+
61+
Loading Credentials Explicitly
62+
------------------------------
63+
64+
In addition, the
65+
:meth:`from_service_account_json() <gcloud.client.Client.from_service_account_json>`
66+
and
67+
:meth:`from_service_account_p12() <gcloud.client.Client.from_service_account_p12>`
68+
factories can be used if you know the specific type of credentials you'd
69+
like to use.
70+
71+
.. code:: python
72+
73+
client = Client.from_service_account_json('/path/to/keyfile.json')
74+
75+
.. tip::
76+
77+
Unless you have an explicit reason to use a PKCS12 key for your
78+
service account, we recommend using a JSON key.
79+
80+
Finally, if you are **familiar** with the `oauth2client`_ library, you can
81+
create a ``credentials`` object and pass it directly:
82+
83+
.. code:: python
84+
85+
client = Client(credentials=credentials)
86+
87+
.. _oauth2client: http://oauth2client.readthedocs.org/en/latest/

0 commit comments

Comments
 (0)