From 1b3d2eb88eba7a2a7b9d6de44a6fc467d7d7ee70 Mon Sep 17 00:00:00 2001 From: Bryan Date: Sun, 14 Jun 2015 23:10:29 -0400 Subject: [PATCH] Removing client_secrets.json as outdated and onerous. Untested. closes 436 --- .env.example | 2 +- README.md | 9 +++++++++ karmaworld/apps/notes/gdrive.py | 7 ++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index f9d7841..3603ed8 100644 --- a/.env.example +++ b/.env.example @@ -9,7 +9,7 @@ CLOUDFRONT_DOMAIN='foo.cloudfront.net' SSL_REDIRECT=true -GOOGLE_CLIENT_SECRETS='{"web": {"json": "goes here"} }' +GOOGLE_SERVICE_EMAIL='numbers-alphanumerics@developer.gserviceaccount.com' GOOGLE_USER='GoogleApps@Email.Address' GOOGLE_SERVICE_KEY_BASE64='Base64EncodedP12FileContentsGoHere' diff --git a/README.md b/README.md index 187d69a..4be9b43 100644 --- a/README.md +++ b/README.md @@ -274,11 +274,20 @@ Follow [Google's instructions](https://developers.google.com/drive/web/auth/web- to create a Google Drive service account. If using Google Apps, it is worth looking at [these instructions](https://developers.google.com/drive/delegation). +Populate the `GOOGLE_USER` environment variable with the email address of the +user whose Google Drive will be accessed. This is typically your own email +address. + Google Drive used to use p12 files by default. Now a new-style JSON file is downloaded by default when creating new credentials. Until the code has been [updated](https://github.com/FinalsClub/karmaworld/issues/437) to use the new-style JSON file, make sure to click the `Generate a new P12 key` button. +While on the Credentials page (with the `Generate a new P12 key` button +visible), note the Service account Email address. It will have a format like +`numbers-alphanumerics@developer.gserviceaccount.com`. Copy this value and +paste it into the `GOOGLE_SERVICE_EMAIL` environment variable. + Convert the p12 file into a Base64 encoded string for the `GOOGLE_SERVICE_KEY_BASE64` environment variable. There are many ways to do this. If Python is available, the diff --git a/karmaworld/apps/notes/gdrive.py b/karmaworld/apps/notes/gdrive.py index 7b95842..12d0f2d 100644 --- a/karmaworld/apps/notes/gdrive.py +++ b/karmaworld/apps/notes/gdrive.py @@ -33,7 +33,7 @@ logger = logging.getLogger(__name__) PDF_MIMETYPE = 'application/pdf' PPT_MIMETYPES = ['application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'] -GOOGLE_CLIENT_SECRETS = os.environ['GOOGLE_CLIENT_SECRETS'] +GOOGLE_SERVICE_EMAIL = os.environ['GOOGLE_SERVICE_EMAIL'] GOOGLE_SERVICE_KEY_BASE64 = os.environ['GOOGLE_SERVICE_KEY_BASE64'] GOOGLE_USER = os.environ['GOOGLE_USER'] @@ -49,12 +49,9 @@ def build_api_service(): https://developers.google.com/drive/delegation """ - # Extract the service address from the client secret - service_user = json.loads(GOOGLE_CLIENT_SECRETS)['web']['client_email'] - # Pull in the service's p12 private key. p12 = base64.decodestring(GOOGLE_SERVICE_KEY_BASE64) - credentials = SignedJwtAssertionCredentials(service_user, p12, + credentials = SignedJwtAssertionCredentials(GOOGLE_SERVICE_EMAIL, p12, scope='https://www.googleapis.com/auth/drive', sub=GOOGLE_USER) -- 2.25.1