ios - 不使用 Firebase 身份验证的实时数据库的 Firebase 规则

标签 ios objective-c swift firebase firebase-realtime-database

我是 Firebase 服务的新手,但我已经完成了负责 Firebase 实时数据库交互的 iOS 应用程序的代码。

现在我想确保我的应用安全并使用 Firebase 规则保护它。有一个问题,我正在为用户使用我自己的身份验证,因此我不使用 Firebase Auth。

所以问题是如何在没有 Firebase Auth 的情况下使用 Firebase 规则保护我的数据库。

最佳答案

注意:据我所知,无法在 Firebase 中直接使用您的自定义身份验证系统。

假设:您有一个集成了 Firebase Admin SDK(可以/已经)的身份验证服务器。

您需要创建自定义 token 才能在数据库/存储中使用您的身份验证:

https://firebase.google.com/docs/auth/admin/create-custom-tokens

Once authenticated, this identity will be used when accessing other Firebase services, such as the Firebase Realtime Database and Cloud Storage. Furthermore, the contents of the JWT will be available in the auth object in your Firebase Realtime Database Security Rules and the request.auth object in your Cloud Storage Security Rules.

从上层链接省略 Java 和 Python

在服务器中:

// Step 1: Your client has sent the credentials.
// Step 2: Fetch the client's unique id, and create a custom token with the Admin SDK.

var uid = "some-uid"; 

admin.auth().createCustomToken(uid)
  .then(function(customToken) {
    // Send token back to client
  })
  .catch(function(error) {
    console.log("Error creating custom token:", error);
  });

然后在iOS部分:

// Step 1: Login with your own authentication system.
// Step 2: Send your credentials to your server, and fetch the customToken.
// Step 3: Sign in with FIRAuth:

[[FIRAuth auth] signInWithCustomToken:customToken
                           completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
  // ...
}];

关于ios - 不使用 Firebase 身份验证的实时数据库的 Firebase 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45586418/

相关文章:

ios - iOS无法设置进度条progress两次?

ios - 如何使用 objective-c 直接在iPhone照片中打开特定相册

ios - swift -IOS : UIalertController position

iphone - 如何检查是否有任何应用程序与文件扩展名相关联

iphone - 扩展 NSManagedObject 实体对象是否安全

ios - 无法使用 DDMathParser 求解数学表达式

swift - 在 Swift 中测试 Decimal 是否为整数

ios - 如何使用 SwiftUI 调用电话

iOS Today 小部件在底部被截断

ios - 尝试构建时出现奇怪的错误