【问题标题】:Firebase Auth with MongoDB Stitch Custom Auth: How to pass user info from Firebase to MongoDBFirebase Auth with MongoDB Stitch Custom Auth:如何将用户信息从 Firebase 传递到 MongoDB
【发布时间】:2020-08-28 02:45:17
【问题描述】:

我正在将 Firebase 身份验证与 Swift iOS 上的 MongoDB Stitch 自定义身份验证集成,并希望将用户的信息从 firebase 传递到 mongodb,以便用户的电子邮件或姓名可以显示在 MongoDB 的控制台上:

基于 MongoDB 的文档,这些可以通过 JWT 的metadata 访问,但我不知道如何从 iOS 添加它们。这就是我从 Firebase 到 Stitch 的身份验证方式:

Auth.auth().signIn(with: credential) { (results, error) in
        if let error = error {
            print(error.localizedDescription)
            return
        }

        if let results = results {
            results.user.getIDTokenForcingRefresh(true) { (tokenId, error) in
                if let error = error {
                    completion(error)
                }

                if let tokenId = tokenId {
                    let credential = CustomCredential.init(withToken: tokenId)
                    stitch.auth.login(withCredential: credential) { (result) in
                        switch result {
                        case .success(let user):
                            print("Sign in to Stitch successful")
                        case .failure(let e):
                            print(e)
                        }
                    }
                }
            }
        }
    }
}

上述验证方法有效,我可以在 Stitch 上成功验证。但是如何从 Firebase 中提取提供者数据并将其显示在 MongoDB 上?

【问题讨论】:

    标签: swift mongodb firebase firebase-authentication mongodb-stitch


    【解决方案1】:

    您必须在用户 > 提供者 > 自定义 JWT 身份验证下配置您的提供者,然后相应地映射字段。

    这张图片

    将像这样映射字段:

    【讨论】:

      猜你喜欢
      • 2019-10-27
      • 2018-06-11
      • 2017-08-28
      • 2021-08-17
      • 1970-01-01
      • 2018-12-16
      • 2021-03-30
      • 2020-11-14
      • 2020-05-18
      相关资源
      最近更新 更多