如何使用Swift中的新Firebase 3.2.1向我的Firebase应用程序验证用户指定提供程序(Facebook,Google)

时间:2016-07-01 20:41:01

标签: ios swift firebase firebase-authentication

我正在更新使用Swift(v2.2)编写的iOS应用程序以使用Firebase 3.2.1。我已更新了我的代码,以使用新API通过我的Firebase应用程序的电子邮件和密码对我的用户进行身份验证。但是,现在看来我还需要更新我的代码才能登录Facebook和Google。在Facebook和Google登录过程完成并且用户已登录到Facebook或Google后,根据旧文档,我还需要使用以下内容将用户登录到我的Firebase应用程序:

  // User is signed in to Facebook!
  // Now, authenticate the user to your Firebase app
  let accessToken = FBSDKAccessToken.currentAccessToken().tokenString
  UserService.firebase.BASE_REF.authWithOAuthProvider("facebook", token: accessToken, withCompletionBlock: { error, authData in
       if error != nil {
          //print("An error occurred!")
       } else {
          //print("User signed in!")
       }

我无法在新API中找到与authWithOAuthProvider()方法类似的方法。请帮忙,谢谢!

  

错误:FIRDatabaseReference类型的值没有成员   authWithOAuthProvider

1 个答案:

答案 0 :(得分:2)

我将此用于Facebook登录,我猜这对谷歌来说几乎是一样的,只需创建一个合适的凭据即可。

let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
        // handle logged in user
 }