From 18f672a778884afdedbb84839dbfc44a2a708857 Mon Sep 17 00:00:00 2001 From: Arthur Thompson Date: Thu, 24 Jan 2019 16:28:47 -0800 Subject: [PATCH 1/2] Use default application credential --- config/README.md | 2 +- config/configure.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config/README.md b/config/README.md index b307eb1..8d6a4d2 100644 --- a/config/README.md +++ b/config/README.md @@ -15,7 +15,7 @@ Getting started 1. [Add Firebase to your Android Project](https://firebase.google.com/docs/android/setup). 2. Create a service account as described in [Adding Firebase to your Server](https://firebase.google.com/docs/admin/setup) and download the JSON file. - - Copy the private key JSON file to this folder and rename it to `service-account.json`. + - Set `GOOGLE_APPLICATION_CREDENTIALS` environment variable to path of downloaded credential file. 3. Change the `PROJECT_ID` variable in `configure.py` to your project ID. Run diff --git a/config/configure.py b/config/configure.py index 8a56f87..b4a48b4 100644 --- a/config/configure.py +++ b/config/configure.py @@ -15,10 +15,13 @@ def _get_access_token(): """Retrieve a valid access token that can be used to authorize requests. + This method assumes it is either running in a trusted Google environment like GCP or if running + elsewhere the the GOOGLE_APPLICATION_CREDENTIALS environment variable is set to the path of the + service account credentials file. + :return: Access token. """ - credentials = ServiceAccountCredentials.from_json_keyfile_name( - 'service-account.json', SCOPES) + credentials = ServiceAccountCredentials.get_application_default().create_scoped(scopes=SCOPES) access_token_info = credentials.get_access_token() return access_token_info.access_token # [END retrieve_access_token] From 8baceeba6072eee0f96fd9e5f89c675eccb73d6a Mon Sep 17 00:00:00 2001 From: Arthur Thompson Date: Wed, 30 Jan 2019 14:06:22 -0800 Subject: [PATCH 2/2] Update docs for _get_access_token --- config/configure.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/configure.py b/config/configure.py index b4a48b4..57faf35 100644 --- a/config/configure.py +++ b/config/configure.py @@ -15,9 +15,9 @@ def _get_access_token(): """Retrieve a valid access token that can be used to authorize requests. - This method assumes it is either running in a trusted Google environment like GCP or if running - elsewhere the the GOOGLE_APPLICATION_CREDENTIALS environment variable is set to the path of the - service account credentials file. + This method must be called in either a trusted Google environment like GCP or if running + elsewhere the GOOGLE_APPLICATION_CREDENTIALS environment variable must be set to the path + of the service account credentials file. :return: Access token. """