title: How to use Google API credentials json on Heroku?
body: <p>I'm making an app using Google Calendar API, and planning to build it on Heroku.<br>
  I have a problem about authentication. Usually I use credential json file for that, but this time I don't want to upload it on Heroku for security reason.<br>
  How can I make authentiation on Heroku?</p>
  
  <p>For now, I put my json to an env variable, and use <code>oauth2client</code>'s <code>from_json</code> method.</p>
  
  <pre><code>def get_credentials():
      credentials_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS']
      credentials = GoogleCredentials.from_json(credentials_json)
      if not credentials or credentials.invalid:
          flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
          flow.user_agent = APPLICATION_NAME
          if flags:
              credentials = tools.run_flow(flow, store, flags)
          else: # Needed only for compatibility with Python 2.6
              credentials = tools.run(flow, store)
          print('Storing credentials to ' + credential_path)
      return credentials 
  </code></pre>
  
  <p>But this code isn't perfect. If the credentials is invalid, I want the code to write the new credentials to the env variable, not to a new file.<br>
  Is there any better way?</p>