Add example for auth with ENV vars (#156)

This commit is contained in:
Alex Filatov 2019-01-22 19:44:56 +00:00 committed by Graham Paye
parent a07011bb45
commit b4516ab3d1
1 changed files with 21 additions and 1 deletions

View File

@ -138,7 +138,7 @@ scope = 'https://www.googleapis.com/auth/androidpublisher'
authorizer = Google::Auth::ServiceAccountCredentials.make_creds( authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('/path/to/service_account_json_key.json'), json_key_io: File.open('/path/to/service_account_json_key.json'),
scope: scope) scope: scope)
authorizer.fetch_access_token! 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" 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 ### Storage
Authorizers require a storage instance to manage long term persistence of Authorizers require a storage instance to manage long term persistence of