首页 > 解决方案 > 如何在 Firebase REST 中设置 databaseAuthVariableOverride

问题描述

Firebase 具有允许使用自定义身份验证变量初始化连接的功能。

示例中的链接:

# Fetch the service account key JSON file contents
cred = credentials.Certificate('path/to/serviceAccountKey.json')

# Initialize the app with a custom auth variable, limiting the server's access
firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://databaseName.firebaseio.com',
    'databaseAuthVariableOverride': {
        'uid': 'my-service-worker'
    }
})

我正在使用 c#,没有针对该语言的 SDK ...。我选择使用 REST API,但我没有在文档中找到如何使用上述代码中的功能。

有一种方法可以在 REST for Firebase 中使用 databaseAuthVariableOverride?

标签: c#firebasefirebase-realtime-databasefirebase-authentication

解决方案


此功能仅在 Firebase 实时数据库的 Admin SDK 中可用,它应该在受信任的环境中运行。

如果您使用的是其他 SDK 或 REST API,它将不可用,因为如果用户可以设置自己的 UID,这将是一个重大的安全风险。

如果您从受信任的环境中调用 REST API,则可以为该调用创建一个自定义令牌,这基本上会给您相同的结果。


推荐阅读