swift - Realm Sync Facebook 身份验证不起作用

标签 swift realm realm-mobile-platform

我尝试在 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 提供的访问 token ,使我能够登录/注册用户。

当我使用 Realm 的库通过 Facebook 访问 token 登录用户时,收到一条错误消息,指出“provider”参数无效,但该参数是由 Realm 自己的类定义的。

我已使用电子邮件和密码成功验证了用户身份,那么我是否需要在 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'!;}

我尝试过的其他事情

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

解决方法是从 Facebook API/SDK 获取帐户信息,并使用帐户的电子邮件通过用户名/密码设置登录/注册。然而,这似乎使得 Facebook 身份验证变得多余。

最佳答案

该 Realm 文档链接已过时。请参阅 3.16.0 文档(或更高版本),因为有很多更改。

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

正如 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.

关于swift - Realm Sync Facebook 身份验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59542787/

相关文章:

swift - 我的类可以覆盖 Swift 中的协议(protocol)属性类型吗?

firebase - 具有 Firebase 身份验证的 Realm 移动平台

android - 无法在写入事务之外修改托管对象(Realm + Android)

swift - 类型 'NSFastEnumerationIterator.Element'(又名 'Any')不符合协议(protocol) 'AnyObject'

ios - 为什么 Swift 自定义 UIActivity 图标图像不显示,而 Objective-C 正确显示?

ios - 我想要自定义的 UITextfield,它具有与 android 相同的占位符行为,我还想要 UITextfield 中的错误标签

android - RecyclerView 在滚动后选择错误的项目 onClick

arrays - Slice<Results> 是否仍然在 Realm 中延迟加载?

ios - 滚动 UITableView 时随机崩溃

java - 如何针对两个条件执行 RealmQuery