iOS Firebase身份验证与其他项目

时间:2020-09-14 08:11:16

标签: ios swift firebase firebase-authentication

我在我的iOS应用中使用Firebase进行分析,云消息传递...并且一切正常。现在,我需要将应用程序链接到另一个Firebase项目以进行Firebase身份验证。此项目是设置Google Cloud Identity平台时在Google Cloud上创建的Firebase项目。我遵循了Firebase指南,该指南介绍了如何configure multiple projects

AppDelegate中,我具有以下代码来配置2个项目:

//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!)

XCode项目中存在默认的GoogleService-Info.plistGoogleService-Info-auth.plist。然后,在视图控制器中,我首先加载第二个应用程序:

let app = FirebaseApp.app(name: "auth")

,然后创建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方案。但是此方案对应于默认项目,而不是我要求使用的项目。我认为这可能是对库的错误检查,并且还为默认项目定义了自定义网址方案,但随后出现以下错误:

[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身份验证设置其他应用程序/项目会出现问题。

你怎么看?

1 个答案:

答案 0 :(得分:1)

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