// 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) {
// ...
}];
2 回答
注意:据我所知,在Firebase中无法使用自定义身份验证系统 directly .
Assumption: You have an authentication server which Firebase Admin SDK (can be/has already been) integrated.
您需要创建自定义令牌才能在数据库/存储中使用您的身份验证:
https://firebase.google.com/docs/auth/admin/create-custom-tokens
从上层链接省略Java和Python
在服务器中:
然后在iOS部分:
史蒂文森说,如果没有firebase身份验证,你就无法使用安全规则 .
要使用firebase身份验证,请按照以下步骤操作
您可以从服务器获取firebase令牌以及您自己的身份验证令牌,然后您可以使用自定义令牌身份验证API(https://firebase.google.com/docs/auth/ios/custom-auth)通过firebase进行身份验证
要了解服务器端的自定义令牌生成,请按照此处,https://firebase.google.com/docs/auth/admin/create-custom-tokens
在实时数据库中存储用户数据的一种常见模式是将所有用户存储在单个用户节点中,其子节点是每个用户的uid值 . 如果您想限制对此数据的访问,以便只有登录用户可以看到自己的数据,那么您的规则将如下所示:
例:
这里 auth 是授权对象 . uid 是您从服务器端生成自定义令牌的唯一令牌(上述用户ID) . 有关详细信息,请查看有关用户安全性的firebase文档 .