From b4516ab3d19eabbd9a1862e7fcf5e48f03fbdb05 Mon Sep 17 00:00:00 2001 From: Alex Filatov Date: Tue, 22 Jan 2019 19:44:56 +0000 Subject: [PATCH] Add example for auth with ENV vars (#156) --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2ede6e..bb112de 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ scope = 'https://www.googleapis.com/auth/androidpublisher' authorizer = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: File.open('/path/to/service_account_json_key.json'), scope: scope) - + authorizer.fetch_access_token! ``` @@ -151,6 +151,26 @@ export GOOGLE_CLIENT_EMAIL=xxxx@xxxx.iam.gserviceaccount.com export GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n" ``` +```ruby +require 'googleauth' +require 'google/apis/drive_v3' + +Drive = ::Google::Apis::DriveV3 +drive = Drive::DriveService.new + +# Auths with ENV vars: +# "GOOGLE_CLIENT_ID", +# "GOOGLE_CLIENT_EMAIL", +# "GOOGLE_ACCOUNT_TYPE", +# "GOOGLE_PRIVATE_KEY" +auth = ::Google::Auth::ServiceAccountCredentials + .make_creds(scope: 'https://www.googleapis.com/auth/drive') +drive.authorization = auth + +list_files = drive.list_files() + +``` + ### Storage Authorizers require a storage instance to manage long term persistence of