如何保护 dialogflow webhook(使用 firebase 函数)?

How to secure dialogflow webhook(using firebase functions)?

我正在开发一个 dialogflow 代理,它在 firebase 函数中具有实现 webhook(使用 Google 客户端库上的操作)。我如何确保只有我的代理才能访问这些功能?

我阅读了以下文档,但没有提供有关其实施的任何进一步细节。

https://dialogflow.com/docs/fulfillment/configure#authentication

It's important to secure your webhook to prevent unwanted, potentially malicious calls. Dialogflow supports two mechanisms for authentication:

Basic authentication with login and password.
Authentication with additional authentication headers.

Dialogflow 提供了这两种方式,使您可以灵活地保护 webhook。

如果您正在使用负载均衡器和 API 网关,或者在您的 webhook 前面有防火墙 - 如果他们不这样做,您可以让该系统阻止对您的 webhook 路径的请求没有将特定 header 设置为特定值,或者如果他们使用系统中没有有效帐户的基本身份验证发出请求。

如果您不使用类似的东西,或者它太难配置,您可以使用这些工具在调用函数本身时过滤掉一些东西。如果您使用的是 actions-on-google 库,则可以在创建 dialogflow object 时 set the verification parameter 强制匹配身份验证或 header,如果它们不匹配,拒绝请求。