Firebase - 删除并重新安装应用程序不会取消对用户的身份验证 [英] Firebase - Deleting and reinstalling app does not un-authenticate a user

查看:122
本文介绍了Firebase - 删除并重新安装应用程序不会取消对用户的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码验证用户(下面是我的代码的修剪版本,所以只显示成功的登录逻辑)...

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




$ pre $ F code $> FBSession.openActiveSessionWithReadPermissions([public_profile,user_friends],allowLoginUI:true ,
completionHandler:{session,state,

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

if error!= nil {
//登录失败
} else {
//登录!
println(Logged in!\(authData))
}
})
}
})
}

(即如果您然后删除应用程序,并重新安装在同一设备上,这个调用 - 我正在使用的应用程序委托确定用户是否登录 - 将永远返回他们登录。

  if firebaseReference.authData == nil {
//未登录
}其他{
//登录
}

为什么呢?如果您在iOS模拟器中重置了内容和设置,并且安装了应用程序,那么

code> firebaseReference.authData 属性将再一次为 nil

解决方案

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.

这篇关于Firebase - 删除并重新安装应用程序不会取消对用户的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆