首页 > 解决方案 > 部署我的应用程序时,我应该将我的 client_secret.json 文件存储在哪里?

问题描述

部署应用程序的新手,所以可能是一个愚蠢的问题,但这是我的问题:

我正在使用 Google 的 Youtube Data API 来获取有关用户喜欢的视频的一些信息,因此我必须通过开发者控制台获取凭据。然后系统提示我下载一个包含我的客户端 ID 和客户端密码等的 json 文件,并将其存储在我的根目录中。

这在开发中很好,我可以看到这个文件,但我的问题是部署到 Heroku 需要我将这个文件上传到 Github,据我所知,从而暴露我的客户端密钥。

显然我不能这样做,所以我希望有人可以分享一些关于如何在部署时访问这个文件的智慧?

这是使用我的代码中的文件作为参考的函数:

@app.route('/handle_redirect')
def oauth2callback():
    # Specify the state when creating the flow in the callback so that it can
    # verified in the authorization server response.
    state = session['state']

    flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
        CLIENT_SECRET_FILE, scopes=SCOPES, state=state)
    flow.redirect_uri = url_for('oauth2callback', _external=True)

    # Use the authorization server's response to fetch the OAuth 2.0 tokens.
    authorization_response = request.url
    flow.fetch_token(authorization_response=authorization_response)

    # Store credentials in the session.
    # ACTION ITEM: In a production app, you likely want to save these
    #              credentials in a persistent database instead.
    credentials = flow.credentials
    session['credentials'] = credentials_to_dict(credentials)

    return redirect(url_for('home'))

CLIENT_SECRET_FILE 位于我的根目录中,但显然在上传到 Github 之前必须将其省略。提前致谢!

标签: herokudeploymentyoutube-data-api

解决方案


推荐阅读