【问题标题】:Email and Password Authentication Without Showing the Password不显示密码的电子邮件和密码验证
【发布时间】:2015-11-14 19:04:12
【问题描述】:

我发现自己需要登录谷歌才能使用远程 api,但是它需要电子邮件和密码来验证该过程。无论如何我可以隐藏它们并要求项目的其他贡献者(安全地)添加他们自己的?

from google.appengine.ext.remote_api import remote_api_stub
import database
import getpass

email = "gmail@gmail.com" #can't show this line
password = "password" #can't show this line

def auth_func():
  return (email, password)

remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', auth_func,
                               'app.appspot.com')

【问题讨论】:

标签: python


【解决方案1】:

您可以将敏感信息保存在环境变量中,并在运行应用程序之前在应用程序文档中包含设置环境变量的说明。

从 Python 中检索变量(来自 here):

import os

email = os.environ.get("GOOGLE_EMAIL")
password = os.environ.get("GOOGLE_PASSWORD")

if email and password:
    # ... process...

如果您使用的是 virtualenv(您应该使用它!),您可能还想使用像 autoenv(或 this 问题中提到的其他工具)这样的工具,它可以为您的单个命令行设置相关的环境变量/ cd 进入项目目录时的控制台会话。

您也可以将命令放在 shell 脚本/批处理文件中,并确保不要提交它。

【讨论】:

    【解决方案2】:

    我会将它放在不同的文件中(例如 config.xml),而不是提交它。您可以在构建您的应用程序之前验证它是否存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-13
      • 2016-05-19
      • 1970-01-01
      • 2020-06-17
      • 2015-08-22
      • 2016-02-11
      • 2020-10-19
      • 1970-01-01
      相关资源
      最近更新 更多