Firebase Auth 验证此用户

Firebase Auth verify this user

我目前正在结合使用 Auth JS SDK 和 Admin Auth SDK 来验证我的用户。我正在采用以下方法: 在前端:

firebase.auth().onAuthStateChanged(function (user) {
  if (user) {
    var current_user = firebase.auth().currentUser;
    current_user.getIdToken(true).then(function (idToken) {
      $.getJSON('/firebase_token', { token: idToken }, function (user) {

在后端:

router.get("/firebase_token", (req, res, next) => {
  admin.auth().verifyIdToken(req.query.token).then(function(decodedToken) {
    res.send(decodedToken);    
  })
})

我想知道这是否是一种安全的方法,因为用户可以从前端发送他们想要的任何令牌。例如,无效用户可以发送他们从有效帐户复制的有效令牌以通过令牌验证。

我想知道是否在管理 SDK 中。有一种方法可以检测当前登录的用户。换句话说,检测 this user 谁在使用带有管理 SDK 的应用程序的 this 实例?

I am wondering if this is a secured approach, because the user can just send whatever token they want from the front-end. For example, an invalid user can send a valid token they copied from a valid account to pass the token verification.

是的,这是可能的。但话又说回来,如果用户可以访问令牌,这意味着他们可能 该令牌所代表的用户,或者他们知道该帐户的凭据。这根本不是问题 - 这就是身份验证系统的工作方式。

I am wondering if in the admin SDK. There is a way to detect the currently signed in user. In other words, detect this user who is using this instance of the app with the admin SDK?

不,Admin SDK 不可能知道使用您的应用程序的所有用户的所有情况。 ID令牌正是它验证用户所需的信息。有效的令牌证明用户是他们所说的人。