简体   繁体   English

Firebase Auth 验证此用户

[英]Firebase Auth verify this user

I am currently verifying my user using the Auth JS SDK and Admin Auth SDK combined.我目前正在使用 Auth JS SDK 和 Admin Auth SDK 组合验证我的用户。 I am doing in the following approach: In the front-end:我正在采用以下方法: 在前端:

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) {

In the back-end:在后端:

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

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.我想知道是否在管理员 SDK 中。有一种方法可以检测当前登录的用户。 In other words, detect this user who is using this instance of the app with the admin SDK?换句话说,检测正在使用this应用程序实例的this user和管理员 SDK?

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.例如,无效用户可以发送他们从有效帐户复制的有效令牌以通过令牌验证。

Yes, that's possible.是的,这是可能的。 But then again, if the user got access to a token, that means they probably are the user represented by that token, or they know the credentials of that account.但话又说回来,如果用户可以访问令牌,则意味着他们可能该令牌所代表的用户,或者他们知道该帐户的凭据。 That's not a problem at all - this is the way authentication systems work.这根本不是问题——这就是身份验证系统的工作方式。

I am wondering if in the admin SDK. There is a way to detect the currently signed in user.我想知道是否在管理员 SDK 中。有一种方法可以检测当前登录的用户。 In other words, detect this user who is using this instance of the app with the admin SDK?换句话说,检测正在使用此应用程序实例的用户和管理员 SDK?

No, the Admin SDK can't possibly know what all is going on for all of the users using your application.不,管理员 SDK 不可能知道使用您的应用程序的所有用户都在发生什么。 The ID token is exactly the piece of information it needs to verify users. ID令牌正是它验证用户所需的信息。 A valid token proves that the user is who they say they are.有效的令牌证明用户是他们所说的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM