2017-10-15 130 views

回答

5

這其實是在Cloud Functions for Firebase documentation提到的關鍵功能之一:

保持您的邏輯私密性和安全

在許多情況下,開發商更希望控制服務器上的應用程序邏輯避免在客戶端篡改。另外,有時不允許該代碼被反向設計。雲功能從客戶端完全絕緣,所以你可以肯定它是私有的,總是正好你想要做什麼

有在火力地堡的functions-samples repo頗有些樣品。

例如,向用戶發送電子郵件確認的樣本需要用於發送電子郵件的gmail憑據。您永遠不希望將這些憑據嵌入應用程序代碼中,惡意用戶可能會發現它們並濫用它們。所以這段代碼是在雲端函數中運行的好選擇。該code that reads these values從這個樣本:

// Configure the email transport using the default SMTP transport and a GMail account. 
// For other types of transports such as Sendgrid see https://nodemailer.com/transports/ 
// TODO: Configure the `gmail.email` and `gmail.password` Google Cloud environment variables. 
const gmailEmail = encodeURIComponent(functions.config().gmail.email); 
const gmailPassword = encodeURIComponent(functions.config().gmail.password); 
const mailTransport = nodemailer.createTransport(
    `smtps://${gmailEmail}:${gmailPassword}@smtp.gmail.com`); 

您可以硬編碼的電子郵件地址和密碼,因爲只有你的項目開發人員將能夠看到它。但在這種情況下,示例會更好,並保留憑藉functions.config()讀取的服務器端配置的憑據。要了解如何設置這些,讀documentation for the sample

設置gmail.emailgmail.password谷歌雲環境變量,如果你的賬戶有2匹配用於發送電子郵件的Gmail帳戶的電子郵件地址和密碼(或應用程序的密碼一步驗證啓用)。對於這一點:

firebase functions:config:set gmail.email="[email protected]" gmail.password="secretpassword" 
0

我想即使API密鑰可以安全地在火力功能存儲。我已經在an articleGithub repo中寫下了我的想法,詳細瞭解如何保存Firebase配置變量並訪問它們。看一看。

相關問題