使用Firebase身份验证进行身份验证时注销Facebook用户

时间:2018-07-20 21:27:48

标签: ios swift xcode firebase-authentication fbsdk

我有以下代码,先通过Facebook然后通过Firebase对用户进行身份验证:

func authenticateWithFacebook() {
    FBSDKLoginManager().logIn(withReadPermissions: ["public_profile"], from: self) { (user, error) in // Signs up user with Facebook
        if let error = error {
            print(error.localizedDescription)
        } else if (user!.isCancelled) { // User cancels sign up
            print("User Cancelled")
        } else {
            self.authenticateFacebookUserWithFirebase(credential: FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString))
        }
    }
}

func authenticateFacebookUserWithFirebase(credential: AuthCredential) {
    Auth.auth().signInAndRetrieveData(with: credential) { (user, error) in
        if let error = error {
            print(error.localizedDescription)
        } else {
            print("Success")
        }
    }
}

此代码按预期工作。用户通过Firebase身份验证后,该如何处理在应用程序中“创建”的Facebook用户?我需要跟踪currentAccessToken并在令牌过期时提醒Firebase身份验证吗?如果不是,我应该仅保留代码,还是应该使用FBSDK将Facebook用户注销我的应用程序?我只是不希望Facebook令牌在我的应用中四处飘荡。

1 个答案:

答案 0 :(得分:3)

用户未使用Facebook这样登录到Firebase。您的应用无法获取用户的Facebook电子邮件和密码凭据,无法将其登录到应用的Firebase。相反,它获取该用户的访问令牌,然后使用该令牌通过Firebase对用户进行身份验证。因此,您无法从Facebook注销用户,但是您可以做的是使访问令牌无效。