Google Auth Accounts Not Displaying Properly on Heroku Intermediate Account

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 , - ?

+4
2

, GOOGLE_PRIVATE_KEY.

Heroku , :

heroku config:add GOOGLE_PRIVATE_KEY="$(cat private_key_file)"

+4

cat printf.

heroku config:add GOOGLE_PRIVATE_KEY="$(printf "-----BEGIN PRIVATE KEY.....")"
+1

All Articles