且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase - 删除并重新安装应用程序不会取消对用户的身份验证

更新时间:2023-12-05 17:46:28

Firebase身份验证会话在iOS密钥链中保留在用户的设备上。当应用程序被卸载时,应用程序的钥匙串数据是



如果您想要手动清除数据,在应用程序中存储一些额外的元数据,并手动调用 FirebaseRef.unauth()来清除持久会话。请参阅#4747404:卸载应用程序时删除钥匙串项目作为额外的参考。


After authenticating a user with the following code (below is a trimmed version of my code, so only the successful login logic is shown)...

let firebaseReference = Firebase(url: "https://MY-FIREBASE.firebaseio.com")

 

FBSession.openActiveSessionWithReadPermissions(["public_profile", "user_friends"], allowLoginUI: true,
    completionHandler: { session, state, error in

        if state == FBSessionState.Open {
            let accessToken = session.accessTokenData.accessToken
            firebaseReference.authWithOAuthProvider("facebook", token: accessToken,
                withCompletionBlock: { error, authData in

                    if error != nil {
                        // Login failed.
                    } else {
                        // Logged in!
                        println("Logged in! \(authData)")
                    }
            })
        }
    })
}

(I.e. Launching and running the app, logging in successfully).

If you then delete the app and reinstall it on the same device, this call - which I am using in the app delegate to determine if a user is logged in - will always return that they are logged in.

if firebaseReference.authData == nil {
    // Not logged in
} else {
    // Logged in
}

Why is that? I would have thought deleting the app and reinstalling it should wipe all data.

If you reset the Content and Settings in the iOS simulator, and the install the app, the firebaseReference.authData property will once again be nil.

The Firebase authentication session is persisted on the user's device in the iOS keychain. The keychain data for the application is not removed when the application is uninstalled.

If you're looking to manually clear the data, you can store some additional metadata along with your application and manually call FirebaseRef.unauth() to clear the persisted session. See #4747404: Delete keychain items when an app is uninstalled for an additional reference.