在Heroku登台帐户中无法正确检索Google Auth凭据

kev*_*arr 4 google-calendar-api heroku google-authentication ruby-on-rails-4

我们选择使用env vars来存储所需的信息,而不是在服务器上存储凭证文件:

GOOGLE_CLIENT_ID
GOOGLE_CLIENT_EMAIL
GOOGLE_ACCOUNT_TYPE
GOOGLE_PRIVATE_KEY
Run Code Online (Sandbox Code Playgroud)

我们获得CalendarService如下授权:

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!
Run Code Online (Sandbox Code Playgroud)

该过程的每个部分都在本地工作 - 授权,获取访问令牌,与API交互等.当我们在Heroku上部署到我们的登台环境时,我们无法通过以下错误:

Unable to read the credential file specified by GOOGLE_APPLICATION_CREDENTIALS: Neither PUB key nor PRIV key: nested asn1 error

我看到了在测试这个错误,所以我知道它可以与任何一个缺失的凭证文件(如错误指示)到一个无效的ID,私钥或电子邮件组合(因为我不小心用了无效的替代私钥值).在那种情况下,错误消息是相同的.

我们已经验证所有vars都与本地使用的凭据相匹配 - 我缺少什么?

小智 5

确保您正确设置了GOOGLE_PRIVATE_KEY变量.

在Heroku上设置多行配置变量需要运行:

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