How to use Google API credentials json on Heroku?

后端 未结 10 1404
深忆病人
深忆病人 2020-12-03 05:36

I\'m making an app using Google Calendar API, and planning to build it on Heroku.
I have a problem about authentication. Usually I use credential json file for that, but

相关标签:
10条回答
  • 2020-12-03 06:21

    As state above, the official Heroku documentation works (https://elements.heroku.com/buildpacks/buyersight/heroku-google-application-credentials-buildpack).

    For PHP Laravel users though, the config variable GOOGLE_APPLICATION_CREDENTIALS should be set to ../google-credentials.json. Otherwise, PHP will not find the file.

    Screenshot from Heroku

    0 讨论(0)
  • 2020-12-03 06:26

    You can create the JSON key file by adding a .profile file to the repo, which will be executed when Heroku starts up the container.

    Set a config variables:

    heroku config:set GOOGLE_APPLICATION_CREDENTIALS=gcp_key.json
    heroku config:set GOOGLE_CREDENTIALS=<CONTENTS OF YOU GCP KEY>
    

    The GOOGLE_CREDENTIALS is easier to set in the Heroku dashboard.

    Create a .profile with a line to write the json file:

    echo ${GOOGLE_CREDENTIALS} > /app/gcp_key.json
    

    Obviously, commit the changes to .profile and push to heroku.


    The recommended buildpack doesn't work anymore and, in any case, this feels more direct without being hard.

    0 讨论(0)
  • 2020-12-03 06:28

    you can change the scripts like this in your packge.json, set the file json path in GOOGLE_APPLICATION_CREDENTIALS

    "scripts": {
        "start": "GOOGLE_APPLICATION_CREDENTIALS=./yourfile.json node app.js"
      }
    
    0 讨论(0)
  • 2020-12-03 06:29

    The buildpack mentioned by Maxime Boué is not working anymore because of the Heroku updates(18+). However, below is a similar buildpack which is working. It is actually a fork from the previous one.

    • Use the below link in the buildpack setting of your Heroku app settings https://github.com/gerywahyunugraha/heroku-google-application-credentials-buildpack
    • Define in Config Vars GOOGLE_CREDENTIALS as key and content of your credential file as Value
    • Define in Config Vars GOOGLE_APPLICATION_CREDENTIALS as Key and google-credentials.json as Value
    • Redeploy the application, it should work!!
    0 讨论(0)
提交回复
热议问题