【问题标题】:Firebase Authentication from Google App Script?来自 Google App 脚本的 Firebase 身份验证?
【发布时间】:2017-08-17 10:07:03
【问题描述】:

我正在尝试将 firebase 身份验证添加到我的 google doc add on。我的目标是有一个侧边栏显示身份验证后来自我的数据库的数据。我对其他答案感到最困惑,因为我不确定 html 文件中的内容与 google app 脚本文件中的内容。我知道我应该创建一个令牌,但是从教程中复制并粘贴该代码后,我迷路了。

部分有用的组/答案:

https://groups.google.com/forum/#!topic/firebase-talk/-RKpHaMPTYQ

Google Authentication with Google Spread Sheet via App Script

https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/tutorials/using-secured-client-authentication-for-real-time-read-and-write-calls

app.html

<html lang="en">
<head>
  <script src="https://www.gstatic.com/firebasejs/3.7.3/firebase.js"></script>
  <script>
  var config = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    storageBucket: "",
    messagingSenderId: ""
  };
  firebase.initializeApp(config);
  </script>

</head>

<body>

<div id="databaseDiv"></div>

</body>
</html>

代码.gs

/**
 * Creates a menu entry in the Google Docs UI when the document is opened.
 * This method is only used by the regular add-on, and is never called by
 * the mobile add-on version.
 *
 * @param {object} e The event parameter for a simple onOpen trigger. To
 *     determine which authorization mode (ScriptApp.AuthMode) the trigger is
 *     running in, inspect e.authMode.
 */
function onOpen(e) {
  DocumentApp.getUi().createAddonMenu()
      .addItem('Start', 'showSidebar')
      .addToUi();
}

function onInstall(e) {
  onOpen(e);
}

function showSidebar() {
  var ui = HtmlService.createHtmlOutputFromFile('app')
      .setTitle('Sow Google Docs');
  DocumentApp.getUi().showSidebar(ui);
}

function makeToken(){ 

  var firebaseUrl = "https://example.firebaseio.com/"; 
  var secret = "EXAMPLEKEYYEKELPMAXE"; 
  var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret); 
  var token = base.createAuthToken(Session.getActiveUser().getEmail()); 
  return token; 

}

我错过了什么?

【问题讨论】:

  • 我不明白你是如何包含 firebase 库的。如果你用谷歌搜索的话,有一个来自应用程序脚本的工作示例。
  • 我确实有firebase library,如果这就是你所指的。我发现的所有示例都没有概述文件中的内容或折旧的内容。你能给我指一个吗?
  • 好的,对不起,最初我以为你想从 .gs 调用 firebase(我已经这样做了),但在你的情况下,它是从前端“常规”使用 firebase,你应该在前端做所有事情.您可能希望将用户电子邮件地址传递到前端,以便更轻松地使用该电子邮件地址从那里启动身份验证流程。
  • 如何从 .gs 调用 firebase?我认为这样会更好。
  • 不,你不想要那个。但谷歌一点,有一个图书馆。

标签: firebase google-apps-script firebase-realtime-database firebase-authentication


【解决方案1】:

不要为应用脚本使用任何自定义 firebase 库,请使用 Official Firebase Inline Javascript Libraries 来实现您的目标。如果您遇到问题,请在此处提出问题(但不要一无所知),人们会提供帮助。

【讨论】:

    猜你喜欢
    • 2011-03-05
    • 2021-10-31
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 2016-09-26
    相关资源
    最近更新 更多