iOS Firebase 身份验证与不同的项目

标签 ios swift firebase firebase-authentication

我在我的 iOS 应用程序中使用 Firebase 进行分析、云消息传递……一切正常。现在我需要将应用程序链接到不同的 Firebase 项目来进行 Firebase 身份验证。该项目是搭建 Google Cloud Identity 平台时在 Google Cloud 上创建的 Firebase 项目。我遵循了 Firebase 指南,该指南解释了如何 configure multiple projects .
AppDelegate我有以下代码来配置这两个项目:

//Configure default project
FirebaseApp.configure()
            
//Configure project for authentication
let plist = Bundle.main.path(forResource: "GoogleService-Info-auth", ofType: "plist")
let options = FirebaseOptions(contentsOfFile: plist!)
FirebaseApp.configure(name: "auth", options: options!)
默认 GoogleService-Info.plistGoogleService-Info-auth.plist存在于 XCode 项目中。然后在 View Controller 中,我首先加载第二个应用程序:
let app = FirebaseApp.app(name: "auth")
然后创建身份验证对象:
let auth = Auth.auth(app: app)
如果看 auth在调试器中,我看到 auth.app已正确配置并链接到第二个项目。但是,当我这样做时:
provider = OAuthProvider(providerID: "providerID")
provider.getCredentialWith(nil) { credential, error in
      if error != nil {
        // Handle error.
      }
      if credential != nil {
        auth.signIn(with: credential) { authResult, error in
          if error != nil {
            // Handle error.
          }
          // User is signed in.
        }
      }
    }
我收到了我没有在 Info.plist 中注册自定义 URL 方案的错误。 .但是这个方案对应的是默认项目,而不是我要求使用的项目。我认为这可能是对库的错误检查,并且还为默认项目定义了自定义 url 方案,但随后出现以下错误:
[auth/operation-not-allowed] - Use of this method requires GCIP. For more information, see the [Firebase API reference](https://firebase.google.com/docs/reference/js/firebase.auth.OAuthProvider)
它告诉我未配置 OAuth 提供程序。我没有在默认项目上配置任何东西,所以这是正确的,但我希望登录需要第二个,我认为库没有这样做。
如果我只在应用程序中配置第二个项目,Firebase 身份验证可以正常工作,因此我假设为 Firebase 身份验证设置不同的应用程序/项目时存在问题。
你怎么看?

最佳答案

provider = OAuthProvider(providerID: "providerID", auth: auth)解决了这个问题。 OAuthProvider还需要配置第二个项目。

关于iOS Firebase 身份验证与不同的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63880464/

相关文章:

ios - 您可以为 iOS 中的默认 "share"屏幕注册您的应用程序吗?

ios - XCode 提示 viewDidLoad 和 "Missing @end"(iAd)

swift - 以编程方式添加到 collectionviewcell 时按钮未启用

ios - 无法在 Swift 3 中使用 nil baseUrl 在 WKWebView 中加载数据?

ios - Xcode 提取重构不起作用 – "Can’ t 提取此选择。”

ios - 如何从多个匹配对象中删除数组中的单个对象

ios - 自定义单元格插入 TableView 时为空白。应用程序关闭并重新打开时不为空白

java - 关于渲染PDF和修改Uri

php - 如何使用现有的 angular2 项目创建 Electron 桌面应用程序

Firebase 云函数服务器端全局变量