Instead of storing the credential file on the server, we decided to use env vars to store the necessary information:
GOOGLE_CLIENT_ID
GOOGLE_CLIENT_EMAIL
GOOGLE_ACCOUNT_TYPE
GOOGLE_PRIVATE_KEY
And we get authorization for CalendarServiceas follows:
scopes = ["https://www.googleapis.com/auth/calendar"]
auth = ::Google::Auth.new_application_credentials(scopes)
service = ::Google::Apis::CalendarV3::CalendarService.new
service.authorization = auth
service.authorization.fetch_access_token!
Each part of the process works locally - authorization, obtaining an access token, interacting with the API, etc. When we deploy to our staging environment on Heroku, we cannot miss the following error:
Unable to read the credential file specified by GOOGLE_APPLICATION_CREDENTIALS: Neither PUB key nor PRIV key: nested asn1 error
, , (, ), , ( ). .
, vars , - ?