我在我的 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.plist
和 GoogleService-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/