python-3.x - 我可以使用 GOOGLE_APPLICATION_CREDENTIALS 代替特定的邮件设置吗
问题描述
我正在尝试通过 Flask-security 设置电子邮件确认,我想知道是否可以使用从https://console.cloud.google.com/apis/credentials/serviceaccountkey获得的 GOOGLE_APPLICATION_CREDENTIALS 而不是设置邮件设置(MAIL_SERVER、MAIL_PASSWORD 等)。
这是我的代码:
class BaseConfig:
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_RECORD_QUERIES = False
SQLALCHEMY_EXPIRE_ON_COMMIT = False
MARSHMALLOW_STRICT = True
MARSHMALLOW_DATEFORMAT = 'rfc'
SECRET_KEY = 'secret_key'
SECURITY_LOGIN_SALT = 'test'
SECURITY_PASSWORD_HASH = 'pbkdf2_sha512'
SECURITY_TRACKABLE = True
SECURITY_PASSWORD_SALT = 'something'
WTF_CSRF_ENABLED = False
SECURITY_REGISTERABLE = True
SECURITY_CONFIRMABLE = True
SECURITY_RECOVERABLE = True
SECURITY_TOKEN_AUTHENTICATION_HEADER = 'Authorization'
MAX_AGE = 86400
GOOGLE_APPLICATION_CREDENTIALS = '\google_credentials_etc.json'
谢谢你。
解决方案
GOOGLE_APPLICATION_CREDENTIALS
is used by the Google Client libraries, and only then, when set as an environment variable. It has no bearing on Flask, nor will the client libraries automatically pick it up from a Flask configuration.
You could json.loads
the service account file and then extract the email, but there's no service information or relay server information in the credentials file.
More importantly, flask-mail
doesn't connect over oauth2. It uses SMTP. I'm pretty Gmail relays are also SMTP. So even if you somehow got an oauth2 token from the service account, you wouldn't be able to use it to connect to the relay server.
推荐阅读
- python - scapy 嗅探功能似乎在监视器模式下不起作用?
- reactjs - 如何处理错误“由于@netlify/plugin-deploy-core 插件中的错误而导致部署失败。”?
- linux - 带有 Elfin EE-10 的 Linux 上的虚拟串行端口
- javascript - SVG 文本元素未显示在图表上
- mysql - 你怎么能把一个表左连接到一个在子选择上连接的表?
- python - 有没有办法在python中命名一个函数和类相同的东西?
- amazon-web-services - 有没有办法按标签列出 CloudFront 分配而不使用 ListDistributions 全部下载?
- android-studio - 我遇到这个错误 java.lang.IllegalArgumentException: 找不到类 java.lang.Object 的调用适配器
- amazon-web-services - 无法使用 localstack dynamoDB 锁定 terraform 状态:UnrecognizedClientException
- javascript - Bootstrap 4 - 在同一页面中有两个轮播会使最后一个项目出现重叠