【问题标题】:Where to store javascript send grid api key safely?在哪里安全地存储 javascript 发送网格 api 密钥?
【发布时间】:2015-12-24 11:12:06
【问题描述】:

在哪里安全地存储 javascript 发送网格 api 密钥?

我有一个 angular2 应用程序,想将 api 密钥存储在安全的地方。 我正在使用 firebase 并且没有像 c# 这样的服务器端代码。

如何最好地在 Angular js 中做到这一点,而不需要有人通过在线源文件查找它。

这是我当前的代码:

 sendGridTestEmail = () => {  
      //TODO - store this in safe place  
      var sendgrid_api_key = "";

      var sendgrid  = require('sendgrid')(sendgrid_api_key);

      sendgrid.send({
        to:       'test@gmail.com',
        from:     'support@gmail.com',
        subject:  'Hello Test',
        text:     'My first email through SendGrid.'
      }, function(err, json) {
        if (err) { return console.error(err); }
          console.log(json);
      });
  }

【问题讨论】:

  • SendGrid JS API 旨在用于服务器上的 Node.js。如果您直接从浏览器使用 API,则无法隐藏 API 密钥。
  • 我查看了 zapier 但无法使其正常工作。你知道其他的选择吗?
  • 您从客户端执行的任何操作对用户都是可见的。就是这样。
  • 你知道我可以让他们难以检索 api 密钥的任何技术吗?加密?将其存储在 Firebase 数据库中?

标签: javascript email firebase angular sendgrid


【解决方案1】:

无法在客户端上安全地存储任何私钥。

您可以运行一个发送电子邮件并存储此 API 密钥的服务器。 AppEngine is one of the easiest ways to run a server with Firebase. AppEngine 上唯一支持的 Firebase 客户端是 Java 客户端。

您可以将 Firebase JVM 客户端与 SendGrid Java SDK 一起使用,并在 AppEngine 上运行。

Here's a tutorial that takes you through the process. The tutorial does build an Android app, but you can use Android Studio for the Google Cloud tools.

【讨论】:

  • 嗨大卫,我需要了解很多关于 java 的知识才能使用它,因为我是前端开发人员并且没有 java 背景?
猜你喜欢
  • 2020-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-19
  • 1970-01-01
  • 2017-07-07
  • 2022-11-16
  • 2020-01-28
相关资源
最近更新 更多