领域同步 Facebook 身份验证不起作用

Realm Sync Facebook Authentication not working

我正在尝试在 Realm Sync 中启用 Facebook 身份验证,但登录时总是出现错误。

我一直在使用这些指南:

  1. https://docs.realm.io/sync/v/3.x/using-synced-realms/user-authentication/additional-providers#facebook

  2. https://docs.realm.io/sync/v/3.x/self-hosted/customize/authentication/included-third-party-auth-providers/facebook-authentication

我有 Facebook API/SDK 提供的访问令牌,使我能够登录 in/sign 一个用户。

当我使用 Realm 的库使用 Facebook Access Token 登录用户时,我得到一个错误,指出 'provider' 参数无效,但这个参数是由 Realm 自己定义的 classes .

我已经使用电子邮件和密码成功验证了用户身份,所以我需要在 Facebook/Realm Sync 上设置其他内容吗?似乎 Facebook 身份验证在 Realm Sync 中不起作用,上面的帮助文件也没什么用。

验证码

func authenticateWithFacebook(facebookToken: String, completion: @escaping (RealmAuthenticationResult) -> ()) {
    let credentials = SyncCredentials.facebook(token: facebookToken)

    print("------FACEBOOK LOGIN-------")
    print("Token: \(facebookToken)")

    login(credentials) { (result, userId) in
        completion(result)
    }
}

private func login(_ credentials: SyncCredentials, completion: @escaping (RealmAuthenticationResult, String?) -> ()) {

    SyncUser.logIn(with: credentials, server: RealmConnection.AUTH_URL, onCompletion: { (user, err) in
        if let _ = user {
            print("User has logged in/signed up")
            return completion(RealmAuthenticationResult.success(true), user?.identity)
        } else if let error = err {
            print(error.localizedDescription)
            return completion(RealmAuthenticationResult.failure(error), user?.identity)
        }
    })
}

错误

Error Domain=io.realm.sync.auth Code=601 "Your request parameters did not validate. provider: Invalid parameter 'provider'!;" UserInfo={NSLocalizedDescription=Your request parameters did not validate. provider: Invalid parameter 'provider'!;}

我尝试过的其他东西

我已经尝试直接实例化基本提供程序 class 'RLMIdentityProvider' 并用它创建 SyncCredentials,但没有成功。

解决方法是从 Facebook API/SDK 获取帐户信息,然后使用帐户的电子邮件登录in/sign,并设置 username/password。但是,它似乎使 Facebook 身份验证变得多余。

领域文档 link 已过时。请参阅 3.16.0 文档(或更高版本),因为有很多更改。

目前密码、JWT 和 Firebase 是唯一的身份验证选项,而 Firebase 身份验证是一个非常可靠的解决方案。集成 Firebase 也包含在使用同步领域 -> 身份验证部分的领域文档中。我不会 link 因为文档现在经常更新。

正如 Realm 团队(多次)所说,广泛的身份验证选项不是优先事项,因为其他公司(如 Firebase)处理得很好。

Realm 论坛上有很多帖子谈到这个,但 Ian 对 this question 的回复非常简洁。

we have and will continue to prioritize synchronization features for mobile

然后

This is why we recommend that a production app should outsource user management and authentication to a company which specialized in these features.