Skip to content

Commit f4c3a32

Browse files
author
Ajay Kannan
committed
Add more detail to README's authentication section
1 parent 561af74 commit f4c3a32

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,19 @@ There are multiple ways to authenticate to use Google Cloud services.
4444

4545
1. When using `gcloud-java` libraries from within Compute/App Engine, no additional authentication steps are necessary.
4646
2. When using `gcloud-java` libraries elsewhere, there are two options:
47-
* [Generate a JSON service account key](https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts). Supply a path to the downloaded JSON credentials file when building the options supplied to datastore/storage constructor.
47+
* [Generate a JSON service account key](https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts). After downloading that key, you must do one of the following:
48+
* Define the environment variable GOOGLE_APPLICATION_CREDENTIALS to be the location of the key. For example, `export GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json`
49+
* Supply the downloaded JSON credentials file when building the options supplied to datastore/storage constructor. For example, `StorageOptions.builder().authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json")).build().service()` returns a `Storage` object that has the necessary permissions.
4850
* If running locally for development/testing, you can use use [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en). To use the SDK authentication, [download the SDK](https://cloud.google.com/sdk/?hl=en) if you haven't already. Then login using the SDK (`gcloud auth login` in command line), and set your current project using `gcloud config set project PROJECT_ID`.
4951

52+
`gcloud-java` looks for credentials in the following order, stopping once it finds credentials:
53+
54+
1. Credentials supplied to the `DatastoreOptions`/`ServiceOptions` builder
55+
2. App Engine credentials
56+
3. Key file pointed to by the GOOGLE_APPLICATION_CREDENTIALS environment variable
57+
4. Google SDK credentials
58+
5. Compute Engine credentials
59+
5060
Google Cloud Datastore
5161
----------------------
5262

0 commit comments

Comments
 (0)